All Questions
32
questions
3
votes
1
answer
238
views
tcsh: Handle spaces in arguments when passing on to another command
I wrote a script that needs to call a command and pass on arguments. My script has its own parameters but some need to be passed through. This fails when arguments to my script have spaces in them.
...
0
votes
2
answers
874
views
How to properly parse a quoted arg-list string in a shell script?
Summary
How to convert a single string a "b" 'c d' $'e\nf' into separate arguments, respecting quotes and preserving whitespaces and newlines?
Question
I'm trying to read and process the ...
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 ...
1
vote
1
answer
611
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 ...
0
votes
1
answer
537
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[@]}"...
0
votes
1
answer
45
views
Script Integer getting prefixed with "
I am running a jar file using a very basic shell script (I literally just need this to run on startup of a NAS). However, I am getting some rather unexpected behavior:
Script looks like this:
java -...
4
votes
4
answers
3k
views
Correctly quote array that is being passed indirectly via another command
I need to pass an array of filenames to a command, preserving proper quoting. So far, so good. Unfortunately the command is actually a sub-command that is, in turn, invoked by another command. ...
2
votes
1
answer
81
views
Generating quoted command arguments
I'm working with a HTTP API that demands a very particular set of signed headers + JSON body. And I really want to cURL it for debugging and sanity in general.
So, I've written a small script that, ...
2
votes
2
answers
1k
views
Keeping quotes passed to a perl wrapper script
I'm writing a small perl wrapper to setup environment variables, etc., then invoke a command by the same name.
./foo.pl -a one -b two -c "1 2 3" -d done
When I output @ARGV, the "" around 1 2 3 have ...
0
votes
2
answers
123
views
Bash : Give builded array to function as a list of argument?
I have this issue with borgbackup, but because the reaction is the same, I will use rsync in my example.
I want to build an array of arguments by adding a prefix to each, and then give that array to ...
2
votes
0
answers
85
views
Bash: Special variables $@ vs. $* in For Loop [duplicate]
Using $@ instead of $* would preserve quoting. Consider the following script:
#!/bin/bash
# Test.sh
for arg in $@
do
echo "I found the argument $arg"
done
./Test.sh "One Two Three"
I reach the ...
3
votes
1
answer
6k
views
Passing arguments with spaces and quotes to a script (without quoting everything)
The following works great on the command-line:
$ ffmpeg -i input.m4a -metadata 'title=Spaces and $pecial char'\''s' output.m4a
How do I parameterize this command and use it in a script/function? I ...
1
vote
1
answer
820
views
How to pipe netcat's output? Problems with xargs and quotes
I'm trying to pipe whatever nc receives with this:
nc -l 20000 | xargs /root/test
...and it works fine, except when xargs receives quoted arguments - it splits them as if they were separate...
...
5
votes
2
answers
2k
views
How to re-write this function to avoid argument injection
I have a function in my .bashrc file that allows me to run a script on a remote server with arguments via ssh.
Currently, the function contains:
function runMyScript {
if [ $1 = "s3" ]
then
...
9
votes
4
answers
3k
views
Can a shell script prints its argument, quoted as you would write them on the shell prompt?
In a shell script, my understanding is that "$@" expands to the script arguments, quoting them as needed. For instance this forwards the script arguments to gcc:
gcc -fPIC "$@"
When using the bash ...