![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
Shell metacharacters
Quote:
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 * Code:
~/foo * Code:
~/foo file1 file2 file3 So what you're thinking of doing is actually Code:
scp $@ user@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 |