homepage Welcome to WebmasterWorld Guest from 54.234.59.94
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Wildcard Expansion of $1 in Bash Function
physics




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

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?

 

jezra




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

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

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

physics




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

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved