Skip to main content

All Questions

Tagged with
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. ...
Ned64's user avatar
  • 8,904
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 ...
Christian's user avatar
  • 101
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 ...
Porcupine's user avatar
  • 2,056
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 ...
david furst's user avatar
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[@]}"...
markling's user avatar
  • 213
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 -...
Nico-Ben de Villiers's user avatar
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. ...
Konrad Rudolph's user avatar
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, ...
Morten Siebuhr's user avatar
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 ...
alfinator's user avatar
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 ...
Vlycop Doo's user avatar
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 ...
sci9's user avatar
  • 527
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 ...
Leftium's user avatar
  • 173
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... ...
user224371's user avatar
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 ...
cpd's user avatar
  • 153
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 ...
Alex Jasmin's user avatar

15 30 50 per page