The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 12:18 PM
Crontab not recognizing the jar files rajuutla UNIX for Dummies Questions & Answers 4 05-01-2008 11:20 PM
Crontab not recognizing the jar files rajuutla Linux 3 05-01-2008 05:27 AM
Crontab not recognizing the jar files rajuutla UNIX for Advanced & Expert Users 0 04-30-2008 03:39 AM
recognizing *.* in find amarnath Shell Programming and Scripting 3 07-17-2006 03:24 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-15-2005
Registered User
 

Join Date: Apr 2002
Posts: 29
recognizing * character

i have a short script that takes a filename and secure copies the file to a remote machine. i'd like to be able to take a * character and secure copy all the files in the directory.

first of all, how would i compare $1 to see if it's a * character?

if [ $1 = '*' ] or [ $1 = '\*' ] didn't do it.

second question is how would i tell the shell script to do 'scp * user@<ip>:/'? or do i have to do it one by one in a loop?
__________________
Unix "is" user-friendly. It's just selective about who it's friendly to.
Reply With Quote
Forum Sponsor
  #2  
Old 11-15-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,656
When you run your script you gotta do:
./yourscript \*
if you just do
./yourscript *
the shell will replace * with a list of filenames before your script even runs.
Reply With Quote
  #3  
Old 11-15-2005
Registered User
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 100
Shell metacharacters

Quote:
Originally Posted by csejl
i have a short script that takes a filename and secure copies the file to a remote machine. i'd like to be able to take a * character and secure copy all the files in the directory.
It sounds to me like you're trying to do the work that the shell already does for you.

Say I cd to /tmp and do ls * . Say it comes back with
file1 file2 file3

Then I create a script in my home directory. Call it foo. Now I cd to /tmp, run the command foo, with * as an argument: ~/foo * . Note that the script "foo" is NOT given a * as an argument. Because what the shell does, before it even executes the command (which is my shell script), is to: Expand variables, Expand metacharacters, and Expand commands in backticks (or $( ...) in ksh ). So when I type
Code:
~/foo  *
, the shell does not run
Code:
~/foo  *
. It expands the *, and really runs
Code:
~/foo   file1 file2 file3
.

So what you're thinking of doing is actually
Code:
 scp  $@ user@ip:
I don't believe you need or want a directory in the "user@ip:" part of the scp because your files will by default be placed in the home directory of user over at your host given by ip.

Finally, I'm not sure of the syntax of the scp command with multiple files. Try doing two of them first, and see if it works. Remember that metacharacters aren't magic, they are pretty ignorant although powerful. What they do is serve as placeholders for a replacement. The shell does the replacing, then and only then does your script or command get the results of the replacement(s).
-mschwage
Reply With Quote
  #4  
Old 11-15-2005
Registered User
 

Join Date: Apr 2002
Posts: 29
thanks for the explanation. you guys are awesome.
__________________
Unix "is" user-friendly. It's just selective about who it's friendly to.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0