recognizing * character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting recognizing * character
# 1  
Old 11-15-2005
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?
# 2  
Old 11-15-2005
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.
# 3  
Old 11-15-2005
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
# 4  
Old 11-16-2005
thanks for the explanation. you guys are awesome.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script program is not recognizing the -w

Sorry I put -r I ment to out -w but its not perform none of -w, -r, -x flags Using centos 6.4 #!/bin/bash echo -e "enter the name of file :\c" read file_name if then if then echo "Type some text date. Tp quit press crtl-" cat >> $file_name ... (2 Replies)
Discussion started by: zbest1966
2 Replies

2. Filesystems, Disks and Memory

Recognizing storage from server

Hi, I need to know what are the storages attached to some of our corporate servers. I run this command from the server only to get a list of WWNs : # /usr/local/bin/evainfo -a Devicefile Array WWNN Capacity ... (1 Reply)
Discussion started by: anaigini45
1 Replies

3. Red Hat

VMBox not Recognizing eth0 on RH.

Hello, I re-installed my laptop and installed a new copy of VMBOX, I created a VM Machine with my Rhel5 and a CEntos copy as well. I am using a laptop HP DV4, I use wireless on the laptop. Usually when I boot up in to either machine I would get eht0 and lo as usual now I just don't get... (4 Replies)
Discussion started by: NelsonC
4 Replies

4. Solaris

Solaris 9 not recognizing CDROM drive

Hello, I've read many posts that offer tips on how to mount a CDROM but I haven't seen any on how to get the system to recognize the CDROM drive. I was transferring files from CDROM to the hard drive successfully. I entered the third CDROM and the system refused to automount it. I tried... (2 Replies)
Discussion started by: TrueSon
2 Replies

5. Shell Programming and Scripting

sed and recognizing a runtime parameter

I thought I posted this before, but cannot see the post, so will re-post. Apologies if it now appears twice ! My script prompts for a 7 digit parameter : read f1 I then run a find command to search for files with $f1 in its contents : find . -print | grep $f1 {file} > temp1 I then run a cut... (1 Reply)
Discussion started by: malts18
1 Replies

6. Solaris

Solaris not recognizing RAID 5 disks

I've just installed Sol 10 Update 9 on a Sun 4140 server and have a RAID 1 configuration (2 136 Gb drives) for the OS and have created a RAID 5 array (6 136 GB) drives. When i log into the system I am unable to see the RAID 5 disks at all. I've tried using the devfsadm command but no luck and... (9 Replies)
Discussion started by: goose25
9 Replies

7. Shell Programming and Scripting

Recognizing an argument in csh

I will be passing an argument to a csh script The script can be either of two forms For example, either script.csh zloc=5/10 or script.csh zloc=5/10/20 So there can be either two values or three values. How can I distinguish which one the user has inputted? I have made... (1 Reply)
Discussion started by: kristinu
1 Replies

8. UNIX for Dummies Questions & Answers

Crontab not recognizing the jar files

Hi All, I am using crontab which execute a shell script. In the shell script, I am executing a java program. This Java program requires the jar files. The cron job file ' cronfile.txt ' contents: MAILTO="raju_utla@dcis.uohyd.ernet.in" 0-59 * * * *... (4 Replies)
Discussion started by: rajuutla
4 Replies

9. UNIX for Advanced & Expert Users

Crontab not recognizing the jar files

Hi All, I am using crontab which execute a shell script. In the shell script, I am executing a java program. This Java program requires the jar files. The cron job file ' cronfile.txt ' contents: MAILTO="raju_utla@dcis.uohyd.ernet.in" 0-59 * * * *... (0 Replies)
Discussion started by: rajuutla
0 Replies

10. Shell Programming and Scripting

recognizing *.* in find

hi folks, I am trying to write a script for deleting all the files which are older than "N" days from current directory. CODE: FileName="*.*" NumDays=-1 echo $FileName echo $NumDays find * -prune -name $FileName -mtime $NumDays -exec rm {} \; Now the problem here is when i... (3 Replies)
Discussion started by: amarnath
3 Replies
Login or Register to Ask a Question