[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: shell program help wanted!



Hi nw x
 1) You should begin your script file with this line:

#!/bin/tcsh

  I assume you use the tcsh shell, for your first instruction is csh
mode. This  way, your script will be interpreted by the /bin/tcsh shell,
whatever the $SHELL variable contains.

  2) See the corrections below, for infos.

nw x a écrit :
> 
> Hi, there:
> I don't think I am in the correct mailing list for this question, but I do
> need help, so if anyone can answer my question, please help me.
> My question is I have lots of files with long name under one directory and I
> want to change the names of the file to temp0, temp1, temp2,...tempN, etc.
> so I wrote the following shell code, but it didn't work (actually, I don't
> know how to make the number at the file name temp?)
> 
> thanks in advances!
> 
> the code is:
> set i=0
> for file in `ls`    # Instead of that...
  for file in `ls .`  # 1st correction ( the $PATH should'nt contain . )
> do
>      if [ -f $file ]; then
>        cp $file ./temp$i    # It should work
>        if [ $? -ne 0 ]; then 
>            echo "copy $file failed"
>        fi
>      fi
>      i = 'expr $i+1'        # Instead of that...
       set i=`expr $i + 1`    # 2nd correction: Comply with the spaces
> done
       exit 0        # Add this 3rd correction ( not necessary really )
> 
In conclusion
  Funny shell programming exercise, no?
  Jean Francois Ortolo





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]