Linked Questions

1
vote
2answers
11k views

Bash flags based on if statements [duplicate]

I am calling a bash script that has a number of flags in the following manner: /home/username/myscript -a -b 76 So to illustrate, the -a flag does something in myscript and the -b flag sets some ...
3
votes
1answer
2k views

Is `echo $TEST` expanding an asterisk in the variable a bug? [duplicate]

Is this a Bash bug? $ mkdir test && cd test && echo "a" > "some.file" test$ echo '*' * test$ TEST=$(echo '*') test$ echo $TEST some.file Why is the second output the resolution of ...
-2
votes
2answers
11k views

Grep a variable in a file [duplicate]

A file is modified by a script using an input file- 141,141_1,BAR,HONDA,ps2_0,unassigned,ps3_0,Unassigned,ps4_0,Unassigned,ps5_0,Unassigned,ps6_0,Unassigned,ps7_3,TILL WILL,..... Input file- ...
1
vote
1answer
2k views

Passing a variable with spaces from bash to awk [duplicate]

I am trying to pass a variable that contains spaces from bash to awk. I have simple a simple script for doing this with single string variables (in which I am searching the first column of the FILE ...
0
votes
1answer
517 views

Bash script to tar – Quoting issue [duplicate]

I have a script that takes filenames as positional parameters. I perform a few operations on these and then tar them. Currently my script is not working. The echo line is there for debugging ...
324
votes
6answers
290k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
226
votes
4answers
49k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
59
votes
9answers
190k views

Can sed replace new line characters?

Is there an issue with sed and new line character? I have a file test.txt with the following contents aaaaa bbbbb ccccc ddddd The following does not work: sed -r -i 's/\n/,/g' test.txt ...
82
votes
6answers
94k views

How can we run a command stored in a variable?

$ ls -l /tmp/test/my\ dir/ total 0 I was wondering why the following ways to run the above command fail or succeed? $ abc='ls -l "/tmp/test/my dir"' $ $abc ls: cannot access '"/tmp/test/my': No ...
140
votes
1answer
56k views

When is double-quoting necessary?

The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of $...
46
votes
11answers
43k views

How do I reuse the last output from the command line?

I'd like to know how to reuse the last output from the console, ie: pv-3:method Xavier$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" /Library/Python/2.6/site-...
66
votes
5answers
99k views

How do I recursively delete directories with wildcard?

I am working through SSH on a WD My Book World Edition. Basically I would like to start at a particular directory level, and recursively remove all sub-directories matching .Apple*. How would I go ...
47
votes
7answers
54k views

Setting IFS for a single statement

I know that a custom IFS value can be set for the scope of a single command/built-in. Is there a way to set a custom IFS value for a single statement?? Apparently not, since based on the below the ...
81
votes
4answers
105k views

Understanding IFS

The following few threads on this site and StackOverflow were helpful for understanding how IFS works: What is IFS in context of for looping? How to loop over the lines of a file Bash, read line by ...
48
votes
4answers
30k views

bash iterate file list, except when empty

I thought this would be simple - but it is proving more complex than I expected. I want to iterate through all the files of a particular type in a directory, so I write this: #!/bin/bash for fname ...

15 30 50 per page
1
2 3 4 5
17