Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

1
vote
1answer
26 views

Broken pipe error when reading stops

I'm trying to make a quick & dirty bash function to compare the audio content of two FLAC files without decoding them into a temp file. With the flac command line tool I'm decoding each file into ...
0
votes
1answer
37 views

How to replace single quotes and &apos in a file

I am trying to replace single quotes in a file and I used the command as sed /s/'//g filename and this command works fine but I have &apos character also in my file and which is not getting ...
1
vote
1answer
49 views

How to allow a bash shell script to loop for 3 retries before exiting (prompt for username/password)

I have a shell script that will ask for username and it will check against a list. if the name is inside the list, it will run another shell script but if the name cannot be found, it will prompt a ...
6
votes
1answer
470 views

What is a *.sorted command and why doesn't it work in my bash?

In a Bash Guide for Beginners (sec. 3.2.1.2. Local variables) there is an example command which is supposed to list all of the local variables, that are not in enviromental variables, or so I think: ...
1
vote
1answer
39 views

“bad array subscript” error when adding entry to an associative array

I thought I'd better start a new query for this, since my original query was fully answered (thank you!). I have two files which are both outputs of a postgresql command. The first ...
0
votes
1answer
19 views

display array in a function - not working

What am I missing here? I have created a simple array: declare -a appArray=( "item1 -a -b" "item2 -c -d" ) If I echo this I can see it all echo ${appArray[@]} > item1 -a -b item2 ...
0
votes
0answers
30 views

what's the use of yes (coreutils)? [duplicate]

I notice my shell has a util named "yes" It just output a infinite "y" string line by line What's the use of this "core util" of "yes" ? Usage: yes [STRING]... or: yes OPTION Repeatedly output a ...
1
vote
4answers
36 views

Testing for any of a family of related values in a Bash variable [closed]

Apologies if this has been answered previously, but I couldn't find much online. Here's what I'm trying to accomplish: if [[ "${hostname}" = (foo | bar)servername(01 | 02 | 03) ]]; then ...
1
vote
4answers
313 views

Does “bash: command: command not found” return false?

I am writing a script to automate the configuration of software. I want to begin by checking to see if the script needs to install the software first, then configure it. If I was to check $ software ...
2
votes
2answers
69 views

How do I rename files using the directory name?

My file structure now is: Input 1 pre.nii 2 pre.nii I would like it to be: Input 1_pre.nii 2_pre.nii From the Input folder, I tried: for i in */pre.nii; do echo $i_pre.nii; done ...
0
votes
1answer
18 views

bash-like last command in history using up-down arrow keys in zsh [duplicate]

In bash, we can use the up and down arrow keys to get the last or nth previous command in history. Can we do this in zsh?
0
votes
1answer
41 views

Some errors are not logged, after redirecting both stderr and stdout to a file

In a Linux server, I run a program and log its stdout and stderr outputs to a file by: myprogram.py > logfile 2>&1 All the outputs to stdout and stderr are logged, except that some errors ...
2
votes
2answers
34 views

Linux bash: Search and replace in file without escaping hassle

Is there any bash solution to do a simple "search and replace" without escaping hassle? I try to replace <!-- JavaScript --> in an html file with the content of a complex javascript file. I ...
4
votes
1answer
67 views

What ${var/a/b/\c} means?

I'm little bit confused about this statement(construction?). I cound't find any sufficient source about this (I do not even know how to call it). What is happening here? bash-4.3$ var="a/b" bash-4.3$ ...
5
votes
2answers
202 views

split a string into path and application

If I have a string such as /home/user/a/directory/myapp.app or just /home/user/myapp.app how can I split this so that I just have two variables (the path and the application) e.g. ...
1
vote
2answers
60 views

Extract Values from Formatted Text

Is there an easy way to extract variables from a text file? E.g. given the output from ab: This is ApacheBench, Version 2.3 <$Revision: 1638069 $> Copyright 1996 Adam Twiss, Zeus Technology ...
7
votes
5answers
118 views

What's wrong with this for loop in bash script?

I am trying to print a simple value for $AR1_p1 but the variable $i is not evaluating. for i in 1 2 3 4 do AR1_p1=22 AR1_p2=23 AR1_p3=24 AR1_p3=25 echo $AR1_p$i done It's like concatenating ...
5
votes
4answers
257 views

convert table to ini file using bash arrays

I have a challenge to take an output file ("inventory.list") in this format: hostname1.env1.domain | abc | environment1 hostname2.env1.domain | abc | environment1 hostname3.env2.domain | abc ...
10
votes
2answers
128 views

What is the difference between &6 and /dev/fd/6?

To read from file descriptor 6 I can use <&6 or </dev/fd/6 (aka /proc/self/fd/6). Usually both work equally well. However if that file descriptor happens to be a socket, strange things ...
1
vote
3answers
61 views

dynamic case statement creation

I have a rather long case statement (about 150 patterns to match). case "$line" in pattern1) ret=result1;; pattern2) ret=result2;; pattern3) ret=result3;; ... ... esac However, this is ...
1
vote
2answers
37 views

How can I run this python script on all html files under a directory? [duplicate]

I have a python script $ cat ~/script.py import sys from lxml import etree from lxml.html import parse doc = parse(sys.argv[1]) title = doc.find('//title') title.text = span2.text.strip() print ...
-1
votes
0answers
12 views

List all files in USB device from /Volumes shell script [duplicate]

To clear things up I have setup folder actions on my mac for whenever a USB device is plugged into my mac it will run a shell script. When I list all files in the Directory /Volumes i get $ ls -a . ...
1
vote
1answer
37 views

How is running a script like an executable different from running it by a shell explicitly?

From A Practical Guide to Linux Commands, Editors, and Shell Programming By Mark G. Sobell Although you can use bash to execute a shell script, this technique causes the script to run more ...
0
votes
1answer
20 views

What the long option “ --debug” suppose to do in bash?

GNU bash, version 4.3.42(2)-release-(i686-pc-msys) Usage: bash [GNU long option] [option] ... bash [GNU long option] [option] script-file ... GNU long options: --debug ...
0
votes
1answer
59 views

Using sed instead of grep to output only matching part of line

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in ...
2
votes
1answer
40 views

How to quickly cd to a command's directory after used the 'which' or 'type' [duplicate]

I want to cd to the directory of go's bin file: $ type go go is /c/tools/go/bin/go How can I quickly cd to this directory in bash ?
0
votes
2answers
22 views

return value of command not displayed in script

If I execute the below rsync command in command-line , I am getting the proper return status /usr/bin/rsync -azv -p /home/zaman x11server:/home/zamanr &> rsyncjob/output."$datetime" echo $? ...
43
votes
4answers
903 views

How does bash differentiate between brace expansion and command grouping?

I've noticed that { can be used in brace expansion: echo {1..8} or in command grouping: {ls;echo hi} How does bash know the difference?
0
votes
2answers
37 views

Is there an equivalent of javascript Math.min() in bash/bc etc.? [duplicate]

I need to convert some javascript calculations to bash, and I am wondering if there is an equivalent function of javascript Math.min() in bash, bc or any other calculator in the shell?
1
vote
2answers
37 views

How i check if a specific number.word exist in a line?

like i have this lines on the file {218394 ted 'y' ted} {131241 john 'n' ted} and i want to check if its y continue if its n dont ! i have this code until now!: read -p "Enter your answer : " echo ...
1
vote
3answers
71 views

What is the definition of a primary in bash?

From Bash's manual 6.4 Bash Conditional Expressions Conditional expressions are used by the [[ compound command and the test and [ builtin commands. Expressions may be unary or binary. ...
1
vote
2answers
33 views

Running Emacs through the value of the bash variable

How would I add a value to a new variable in bash, so that when I echo the variable Emacs would run?
5
votes
2answers
68 views

In bash script, what's the different between declare and a normal variable?

In bash scripting: we create variable just name it: abc=ok or we can use declare declare abc=ok what's the different ? and why bash make so many ways to create variable?
1
vote
1answer
43 views

one-dimensional array in shell not working for indexes greater than 08

I have been wondering why the one-dimensional array in shell isn't working for the sub-script / index 08 and 09. How come this happen? $ cat check month_arr=(0 31 30 31 30 31 30 31 31 30 31 30 31) ...
10
votes
3answers
280 views

How to extend bash aliases

How to create an alias that actually extends another alias of the same name in Bash? Why: I used to have GREP_OPTIONS set on .bashrc to something like this: GREP_OPTIONS="-I --exclude=\*~" I also ...
0
votes
1answer
12 views

rename all files in a folder deleting duplicate string-parts

I have a folder with lots of subfolders, that contain two times the same but slightly different: Movie1 {Action}{Adventure}{Sci-Fi}{Thriller}{Science Fiction}/ Movie2 ...
-1
votes
2answers
58 views

Is this good in order to have an empty directory?

I would like to have a directory mydir with empty content, but I don't know in advance if it already exists, or when it does, if it is empty. So my way is mkdir -p mydir ...
0
votes
2answers
35 views

Use a shell variable with Awk

I have this: if [[ $1 = "-c" ]] && [[ $2 =~ ^[a-z A-Z]+$ ]] then awk -v var="$2" '{print $2}' something.txt fi What I want is with a comand like -c abc to show the lines in something.txt ...
-1
votes
0answers
23 views

How can i list a specific line/word from my text?(shellscript)

I have this until now: if [[ $1 = "-s" ]] && [[ $2 =~ ^[0-9]+$ ]] echo "ok" for $2 = 1 awk {print $1} something.txt fi what i want is when for example when i enter -s 2 to list the second ...
2
votes
3answers
172 views

Can I put ranges to parameters? [duplicate]

I have this code: if [[ $1 = "-s" ]] && [[ $2 = 0-9 ]] then echo "yes" fi 0-9 does not work for me. What I really want is to type, for example, -x 3 (or any number).
1
vote
1answer
52 views

Get absolute path of file OS X

I am creating a script which will prompt the user to enter a location of file and it will convert it to an absolute path. This is what I have so far. I'm not sure how to append these together. ...
4
votes
0answers
35 views

making file immune from a non-privileged script

Is it possible from a bash running as a non-privileged user to mark the file immune so it cannot be altered in any way from any process running as that user? It is OK if other users or a root can ...
0
votes
0answers
21 views

Array Creator Bash OS X not expected output

I am creating a script which will prompt a user to enter a location of a text file and based from that it will create an array. First Question The text file that I am using is sample.txt and it is ...
0
votes
1answer
65 views

Strange directories in /home

There are some strange directories appearing in /home (so far, maybe in other locations too). These directories do not show up in ls but do with bash's tab autocomplete, when doing things like cd. ...
0
votes
1answer
45 views

How to count the number of files in current directory that contain a specific phrase? [duplicate]

I want to count number of files in current directory that contain the phrase "HW". I tried ls -l | grep HW | wc -l
3
votes
1answer
41 views

convert a jpg file after being uploaded using inotifywait

First it is my first time writing a bash script so I apologize if this is trivial. I am trying to setup a watch so every time a jpg file is uploaded to a specific folder, it gets converted to webp ...
1
vote
2answers
45 views

Ruby gems not recognized in bash script

I have built a node.js app that listens for webhooks. Currently it is used to build a jekyll website. I have configured it on my server and jekyll build works perfectly when I run it in the root of ...
3
votes
1answer
45 views

Colored Output from Bash Script

I'm running grep inside a bash script. If I run the grep command directly, I see colored output of the file name and search string: grep -i username /tmp/sess_* If I put that command in a bash ...
1
vote
5answers
56 views

Filtering out inputs to textfile

I am using and Raspberry Pi (running raspbian) and I have a shellscript continuously outputting values into textfile via this command: wavemon -d |grep -i signal >> textfile.txt The output is ...
1
vote
1answer
32 views

Password Generator not working OS X

I am creating a Password Generator using 4 Arrays (Lower Case, Upper Case, Symbol and Number) with the RANDOM function. Basically I will generate a random number and then apply it to each of those ...