It is currently Tue, 07 Dec 2021 03:14:39 GMT



 
Author Message
 Unknown behaviour in shell
Hi,
I am trying to write a shell script like this:
*****************************************
#!/bin/sh
#mycopy.sh
copy=1
for a in $*
do
        echo $a
        echo "cp $a $HOME/$a_$copy"
done
*****************************************

When trying to execute this as:
$mycopy.sh file.c
The output is:
file.c
cp file.c /u/rsamik/1

I am expecting it to be: cp file.c /u/rsamik/file.c_1
Why is this behaviour, and what I should do to get the result as
expected?
Regards.
Samik.

Sent via Deja.com
http://www.**-**.com/



 Mon, 21 Jul 2003 13:42:24 GMT   
 Unknown behaviour in shell

echo "cp $a $HOME/${a}_${copy}" will do the job ...

Regards

--
Alcatel Kommunikations-Elektronik GmbH        http://www.ke-online.de
Peter Michalicka                              Tel. +49-511-6747-192
Wohlenbergstr. 3, D-30179 Hannover            Fax. +49-511-6747-340

  peter.michalicka.vcf
< 1K Download


 Mon, 21 Jul 2003 16:44:59 GMT   
 Unknown behaviour in shell
Try: echo "cp ${a} ${HOME}/${a}_${copy}".
Your problem is that the variable $a_ has no value.

HTH.
--

Regards/MfG
Roland Titze



 Mon, 21 Jul 2003 16:31:50 GMT   
 Unknown behaviour in shell

An underscore is a valid name character. So the shell
sees "$a_" as a variable you never defined. Use
"${a}_$count". Then "man sh" and read _all_ about
variable definition and substitution.



 Mon, 21 Jul 2003 23:02:00 GMT   
 
   [ 5 post ] 

Similar Threads

1. S1692DL Tiger 2 unknown PCI bridge :unknown Host bridge :unknown PCI Device

2. Strange shell script behaviour

3. Odd shell behaviour

4. Awk: behaviour of string obtained from shell.

5. Odd shell behaviour ?

6. Behaviour of the shell (ksh)

7. xterms default behaviour for shells (sorry, once again)

8. Odd shell behaviour


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software