Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

1
vote
1answer
55 views

Install command if command doesn't exist [closed]

I have this set up in a Makefile. ARG_2 := $(word 2, $(MAKECMDGOALS)) command_exist=command -v $(1) >/dev/null 2>&1 command_not_exist=! command -v $(1) >/dev/null 2>&1 npmig: ...
1
vote
1answer
44 views

script ssh login to server and pass root password

I have written an expect script to automate the login process for ssh. My user account has rsa keys setup but once I log in I want to switch to root but the remote server is hanging on the password. I ...
0
votes
1answer
34 views

Can't remove apostrophes from filenames in terminal [duplicate]

I don't understand why zsh and bash (ls) show me lots of filename inside apostrophes, but not all: 'joe rilla - mauern fallen.mp3' jokaz-alarmbereit.mp3 'yoshi blessed - everybody free.mp3' I tried ...
-1
votes
2answers
89 views

How do I grab image dimensions using ImageMagick cli?

I am having issues with the part of the following script where it takes the inputted image and checks its dimensions. If it's not a certain dimension then it resizes the image. My issue is what would ...
0
votes
0answers
26 views

script to remotely change uids in linux [duplicate]

im writing a script to remotely change uids over ssh and it kinda works, but only the first pass through the loop works.. here is my script, #!/bin/bash<br> servers="server1 server2"<br&...
1
vote
1answer
37 views

Loop through read only .zip data archive to extract line from .kml file within [duplicate]

I am trying to access some satellite data on a read only archive. I am only interested in files with certain co-ordinates listed in a .xml within the zip that match my research area. There are ...
2
votes
3answers
218 views

Append data of multiple files to new file separated by a line

I have more than a hundred firewall rules for many different customers in discrete files in a folder. Suppose the filenames are: 1.wawa.com_firewall_rule 2.newa.com_firewall_rule Each file ...
0
votes
2answers
38 views

What's the proper way to use a variable with spaces in part of a shell script command? [duplicate]

How can I include spaces as part of a variable used in an svn command for RHEL bash scripting? Or if there's something else wrong with the following, please advise. The SVN URL variable has no spaces,...
0
votes
1answer
37 views

How to save the grep o many files

I am using grep to catch a part of many files, which has name 001.log, 002.log, 003.log .... I need to save the grep as a different file grep -A3406 -P 'Molecular' *.log And to output the grep ...
2
votes
2answers
86 views

Use env with environment variables from file

Let's say I have a file (called e) with this content: a=3 b="5 6" How can I get each one to be interpreted as a separate argument to env? That is, to have it equivalent to: $ env a=3 b="5 6" ...
3
votes
2answers
31 views

Build a process substitution list for tee

I have a script like this which I use to broadcast commands to several instaces of the postgresql database CLI connected to several different servers. I'm using a hard-coded set of process-...
2
votes
0answers
24 views

Issue with adding a function to the .profile [closed]

I added the following to the ~/.profile: #Change desktop background f(x) function changeBackground() { FILE="'file://$(readlink -f "$1")'" echo changing to "$FILE" gsettings set org.gnome....
0
votes
1answer
30 views

How to use 7z and “for file” with multiple file inputs?

I have multiple files in a folder like: 1.txt 2.txt 3.txt ... 100.txt And I want to use 7z to compress single files, generating 1.7z, 2.7z 3.7z... I'm trying to use for file in {1..100} ./{1..100}....
1
vote
1answer
30 views

bash - aliased command - use original command? [duplicate]

I have ls aliased to ls and some flags, however, I want to use the original, 'vanilla' version of ls in another alias. Is there a way for me to call the original version of ls?
2
votes
1answer
50 views

How to choose the highest number element in many files with many arrays

I have many files which each one contain many arrays(like input 1 and 2, below). Each array has two element numbers in the second row. I need to use a logical criterion to choose the highest number ...
0
votes
2answers
40 views

Sum column numbers elements in many arrays

I need to sum the the numbers located in the same column in an array. The input is: 1: 6.1703 44 3.5 0.3 46 7.3 2.3 2: 6.1932 44 5.29379 2.9 46 1.72261 7.2261 3: 6.5664 45 4.756 5.6 46 1.6 2.5 4:...
0
votes
2answers
75 views

A do nothing line in a bash script

I have a bash script and I have an else statement which I want it to do nothing. What is the best way to do this?
2
votes
1answer
123 views

Why does ci" (change inside quotes) not work in bash with vi mode enabled?

My favourite way to use bash is with readline's vi mode, enabled with set -o vi. It works perfectly for me, except that ci" does nothing. The change inside X feature does not work. What can I do to ...
0
votes
1answer
40 views

ffmpeg bash script segment template

I was trying to control ffmpeg file segment function through a bash script to cut a large movie file into smaller pieces. I took a look at the documentation here but this doesn't really cover what I ...
1
vote
1answer
38 views

How to generate a set of new different files through shell scripting given a certain pattern name?

How to generate a set of new different files through shell scripting given a certain pattern name? Said I have this pseudocode: #!/bin/bash for i in {1..5} do ./processing < base.ppm > ...
1
vote
2answers
26 views

bash : export: `PATH:home/pi/netkit/bin:/usr/local … invalid indentifier [duplicate]

Currently I'm struggling with some notification every time I open terminal: bash: export: `PATH:home/pi/netkit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:bin:/usr/local/games/:/usr/...
1
vote
1answer
37 views

cd to previous directories [duplicate]

I'm running CentOS 7, but hoping there is a general Linux way of doing this. So you can cd back and forth between the previous and current directory with this: cd - Is there I way can cd back ...
1
vote
2answers
37 views

Automatic backup and exclude of certain folders

I have created the follow bash script to be used in Cron for automatically backing up certain folders,...while also excluding certain sub folders: folders_to_backup=( "/fist/folder/to/backup/" ...
2
votes
1answer
40 views

Why doesn't grep give me the all found strings?

I have txt file whose inside there are 8 times "ATOMIC_POSITIONS" string and when I'm trying to write each one of them with ; AtomicPos=$(grep -n "ATOMIC_POSITIONS" hw1_out_si_wire.txt) echo $...
0
votes
2answers
33 views

How can I assign the last element of an array to a another array?

Let say I have an array $Info whose elements are ; ! total energy = -1090.13343774 Ry ! total energy = -1090.20757070 Ry ! total energy = -1090....
1
vote
1answer
45 views

Script to send mail using function

I am trying to write a bash script with a function which you use to send an email from the command line to an address and include a Cc address, a subject line, and an input file. For example, if the ...
1
vote
3answers
38 views

Extending Linux terminal Program [closed]

Any quick ideas on how to write a program that extends the terminal's basic functionality? I want to do everything the terminal does but additionally do some custom processing on whatever the user ...
2
votes
1answer
21 views

Strings from two distinct arrays not matching?

I'm trying to filter one array from another array. That is, I'm trying to create a third array with a logical not-intersection. The best I can tell, it appears this block of code never matches, and ...
1
vote
1answer
43 views

How to add numbers in many arrays

I have a file with many arrays, which has "identifiers" numbers in the first column. So I need to sum the numbers located in the second column based on that "identifiers" . An example of the input: ...
-4
votes
2answers
100 views

What is wrong in this code? [closed]

The code is ; cm=$1 nm=$2 case $cm in "out") declare -a en declare -a inf ec=$(grep -n "! " hw1_out_si_wire.txt) IFS=$'\n' en=($ec) lst=$((${#en[@]} -1)) IFS=' ' inf=($en[$lst]) echo " Energy: ${inf[...
1
vote
1answer
44 views

Will these commands return the same output on different Linux distributions? [closed]

I am writing a monitoring script. I am running it on a specific machine, and it works. It is planned to be ran on several Linux machines, not bound to a single distribution. Here are the commands and ...
1
vote
1answer
67 views

Bash Function Parameters - Spaces in Filename [duplicate]

I know there are rules for quoting parameters, but no matter what I try, I can't seem to figure out how to make this work. I have a function that takes a single filename as a parameter, then uses ...
0
votes
1answer
48 views

Bash script to install package if already not installed (From a directory with many packages) - Fedora 17

I have a directory full of rpms (And their dependencies). Currently I am executing yum localinstall ./packages_directory/*.rpm to install all packages in there. It automatically skips the ones already ...
-1
votes
1answer
66 views

How to compose a list of all the executables that are used in a bash script?

Executables as a general term for: common binaries scripts I suppose it can be done with some fat regex, matching start of new lines, conjunctions like && and ||, inline after ; etc...but ...
1
vote
4answers
110 views

Bash script to check if a file is modified or not

I try to write script to check if a file was modified or not. If it did, it should echo "Error!", if not - script keeps running. My script #!/bin/bash date=$(stat -c %y)$1 while true do ...
2
votes
1answer
65 views

substring removal in find -exec

When using $ find . -name string~ -exec cp {} FOO \; is there a way to use {} in FOO to remove the tilde character as we usually do with bash substrings e.g. : $ echo ${string%substring} I ...
1
vote
4answers
91 views

Why is this code not working?

I'm trying to take such a output like; $ sh mod-date-pattern.sh sun The file sun1.txt was modified on 2007-10-01 at 01:26. The file sun2.txt was modified on 2007-10-01 at 19:10. The file morning-sun....
1
vote
4answers
56 views

How to open or list all files whose names match two patterns in Bash

Suppose that I have a directory with thousands of files; how could I open all files whose names contain the strings "red" and "green"?
6
votes
2answers
103 views

Why does Bash ignore SIGINT if its currently running child handles it?

The following Bash loop stops if I interrupt it with ^C: (while true; do sleep 5; done) The following, however, does not: (while true; do aplay test.wav; done) The difference, from what I can ...
2
votes
3answers
63 views

Mysql output format in Bash Script

I'm writing a bash script where I'm using mysql query in that script where the format which I'm getting is quite different. Query: root@debian:~# mysql -u root -ptoor super_market -h 0 -e "select * ...
1
vote
1answer
45 views

Combining Bash Script and Script Resources into One Executable

When trying to execute a bash script, it is often execute inside some directory, and requires access to local resources. I was wondering if there was a way to combine both the bash script and the ...
2
votes
1answer
17 views

Sending notifications from irssi to wmii

So this is two questions in one. Simply setting PROMPT_COMMAND='echo -ne "\033]2;BLAH\007" will change an xterm titlebar to the string "BLAH", even under wmii. Of course, I can also change the ...
0
votes
2answers
25 views

Preventing command substitution from evaluating when appending to a file

How can I stop the eval statement from evaluating when it's being appended to a file as part of a cat << __EOF__ command? TL;DR I manage services on a large number of Linux servers. ...
2
votes
1answer
45 views

Putting subshell in background vs putting command in background

I have two bash scripts that try to check hosts that are up: Script 1: #!/bin/bash for ip in {1..254}; do ping -c 1 192.168.1.$ip | grep "bytes from" | cut -d" " -f 4 | cut -d ":" -f 1 & ...
0
votes
1answer
27 views

bash script controlling ffmpeg to convert from mkv

Help me debugs this script to create control ffmpeg from a bash script. for f in $FILES do INPUT_MOVIE=`basename "${f%.*}.mkv"` OUTPUT_MOVIE=${MOVIE:1} OUTPUT_MOVIE=${OUTPUT_MOVIE:0:2}") ...
0
votes
3answers
52 views

How to remove poorly named file [duplicate]

I was using pscp to copy files from a Windows machine to a Linux machine. I accidentally got the path wrong and now there are files that I can't seem to remove. I think it is because of the slashes in ...
0
votes
0answers
34 views

sum of numbers located in different rows using awk

The following lines sum numbers located in the row #2 and row #3 , row #4 and row #5, row #6 and row #7 and so on (so, sum in a consecutive way). awk ' NR==1{$1=$1; print; next} !(NR%2){split($0,a);...
7
votes
4answers
125 views

How do I determine if a program is running when I start a shell and start that program if it is not already running?

When I start a shell, in my case bash and/or zsh, what lines do I need to add to .zshrc and/or .bashrc to check to see if a program is already running, and if the program is not already running, start ...
-1
votes
1answer
31 views

Evaluate a unix command within for loop [closed]

I wish to print from i.res to POSCARi+1. i.res are files with names 1.res, 2.res, 3.res, etc. These files are sitting in the working directory. POSCAR(i+1) are files with names POSCAR2, POSCAR3, ...
2
votes
2answers
20 views

Simple Korn shell script needed to list out all files created/modified after tidemark date

How to list out all files created/modified after a particular tidemark date? If my tidemark date is '30-May-2016 08:06:49' then I need all files/directories generated/modified after that date&time....