All Questions
503
questions
6
votes
1
answer
702
views
Script not working when passed to bash via -c
Why does this work:
$ cat test.sh
#!/bin/bash
cat <(date|awk '{print $1}')
$ ./test.sh
Thu
but not as a command passed to bash:
$ bash -c "cat <(date|awk '{print $1}')"
Thu 2 Apr 2020 12:52:...
1
vote
2
answers
373
views
How can I parameterise my command in a bash script file?
Edit -- Not using bash $1 variables. Example is using field designators: $1, $2, $3 are the awk input record fields Unfortunately I did the example too quickly and mixed-up the example.
I believe ...
0
votes
1
answer
246
views
Backticks evaluation problem in quoted command, in su -c, in heredoc, fed into 2 layers of ssh
I have the following chain of indirection:
ssh -t root@host1 ssh host2 << EOF\nsu - user2 -c 'kill `cat ~/file_with_pid`'\nEOF
In the end what I need is just to kill a process (reading the pid ...
3
votes
2
answers
954
views
Globbing within a parameter expansion
I'm trying to select the files within a set of directories passed as arguments with the following:
${@/%/*}
However, this is not ideal, since paths with spaces will break, and quoting the parameter ...
0
votes
1
answer
309
views
Quoting a command line argument containing a variable that may have both single and double quotes in its expansion
After some unsuccesful attempts at quoting the command string correctly, I ended up using the below command to run the identify command on the .jpg files under the working directory, the names of ...
5
votes
3
answers
1k
views
Find exec sh: Shell variable not getting passed to subshell
Here is a simplified code that prints the name of Directory if it contains a Filename with same name as the parent directory and .md extension.
FIND(){
find . -type d -exec sh -c '
for d ...
0
votes
3
answers
736
views
Utility to add quotes to argument
I have an issue which can be solved with utility to add quotes to argument and output to standard. I did a web seach for "linux utility to add quotes to argument" and found nothing relevant. Is there ...
2
votes
1
answer
231
views
Single quote problem in "sh -c" script launched from "find"
Now I am writing a script for a long time, but lately this problem has drives me crazy. I tried everything but couldn't solve it.
find . -iname "*.mp4" -type f -exec ffmpeg -i "{}" -c:a "$ACODEC" -c:...
1
vote
1
answer
616
views
problem escaping quotes in script
I'm constructing a command line for use with the 'mogrify' tool [part of imagemagick]. the finalised command line looks something like this :
mogrify -stroke yellow -draw 'line 0,0 0,319' -draw 'line ...
-1
votes
1
answer
169
views
Bash ANSI C quoting not correctly quoting newlines
ANSI C Quoting in bash is supposed to read strings the same way C(or python with single quotes) would.
printf $'"Hello, World!\\n"'
#expected output (no newline, the slash is escaped)
"Hello, World!...
0
votes
1
answer
542
views
Why do these rsync filter args fail in bash when passed in array?
Why does this rsync command work when I give it literally but not when I create it from variables?
Here are the variables - first the options I'm passing to rysnc, as an array:
$ echo "${options[@]}"...
4
votes
2
answers
1k
views
Is there a way to printf $@ verbatim?
I want to write a script that echoes to stdout its $@ verbatim, including any potential double-quotes, without a newline.
What I have tried:
> cat ./script1
#! /usr/bin/bash
printf "%s %s" $0 ...
3
votes
1
answer
2k
views
prevent single quotes in bash script
I have a bash script that's just a shortcut to the grep command. I call it like this:
stx -p /var/www -t 'my text'
This would run this command:
sudo grep -rinI /var/www -e 'my text'
I'm trying to ...
0
votes
2
answers
484
views
Quoting directory names in bash prompt
I want to quote the current directory in my prompt.
Eg, if I do:
mkdir $'new\nline'; cd $'new\nline'
I want my prompt to display $'new\nline', and NOT print a literal newline.
I'm seeing ...
4
votes
1
answer
788
views
Prevent awk from removing "\" (backslashes) in variable
I have this line of code for the shell:
ls -1 *.mp3| awk -v here="$(cygpath -w $PWD)" -v source="$source" '{print "File Name: "$0"\n"here"\n"source}'
Unfortunately it outputs:
File Name: Data 00053....