All Questions
9
questions
0
votes
2
answers
476
views
Pass qouted filename with spaces in a bash variable [duplicate]
In a bash shell, consider this:
$ x="-name 'foo bar'"
$ find $x
find: paths must precede expression: `bar''
$ find -name 'foo bar'
./foo bar
What can I put in $x to make find $x behave like ...
1
vote
1
answer
521
views
sed bash script is unexpectedly replacing character with space instead of newline [duplicate]
Using bash command syntax:
echo "The*quick*brown*fox"|sed s/*/\\n/g
I get the desired output:
The
quick
brown
fox
However in script:
IN_TXT="The*quick*brown*fox"
OUT_TXT=$(echo $IN_TXT|sed s/*/\\...
0
votes
1
answer
401
views
script parameter containing spaces invoking mediainfo
I'd like to create a small shell script that will tell me the duration of a video whose file name is passed to it as a parameter. It'd be something like this:
$ script_name "file name with spaces....
4
votes
2
answers
451
views
Maintain filenames as separate arguments in successive commands
A disclaimer: This isn't related to one specific command like ls or grep, although I use them in the examples, this is more a bash thing.
Let's say I want to see the file sizes, timestamps, and ...
10
votes
4
answers
4k
views
Why does cut fail with bash and not zsh?
I create a file with tab-delimited fields.
echo foo$'\t'bar$'\t'baz$'\n'foo$'\t'bar$'\t'baz > input
I have the following script named zsh.sh
#!/usr/bin/env zsh
while read line; do
<<<$...
1
vote
1
answer
1k
views
bash error on eval containing blank space
I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this:
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
On test....
1
vote
1
answer
841
views
Pass list of directories (that contain whitespaces) to a command in a script
For example, I want to execute the following within a shell script:
tar cvpzf /destination/backup.tgz /directory\ one /directory\ two
I wish to assign the list of paths (with whitespaces in them) to ...
375
votes
6
answers
409k
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 ...
14
votes
2
answers
8k
views
Quoted vs unquoted string expansion
for i in $(xrandr); do echo "$i" ; done
for i in "$(xrandr)"; do echo "$i"; done
for i in "$(xrandr)"; do echo $i; done
I understand why 1 differs from 2. But why does 3 give a different output from ...