Welcome to WebmasterWorld Guest from

Forum Moderators: bakedjake

Message Too Old, No Replies

Wildcard Expansion of $1 in Bash Function



6:57 pm on Sep 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

The following function works well when I want to scp one file back to my laptop:

function scpme()
scp $1 me@${SSH_CLIENT% * *}:./$2

However, when I specify a wildcard like
scpme *.pdf
the *.pdf gets expanded out into the first .pdf file name in the directory, e.g. aaaa.pdf.

When I do
scp *.pdf me@x.x.x.x:./
it does copy over all of the files.

I tried escaping the *, enclosing *.pdf in quotes, etc. but no luck. Searching for the answer proved fruitless.

Basically all I need to know is how to get bash to not expand the input to the funciton out and pass it to scp as *.pdf. Any ideas?


9:03 pm on Sep 25, 2006 (gmt 0)

10+ Year Member

You will need to loop through the input arguments in your script with something like the following:

function scpme()
for i in $*
scp $i me@${SSH_CLIENT% * *}:./


9:20 pm on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Thanks for the tip but I'd also like to be able to do this with rsync so would rather not spawn a different job for each file. So does anyone know how to get at the unexpanded *.pdf when that's passed into a function?

Featured Threads

Hot Threads This Week

Hot Threads This Month