|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Shell Scripting
Need help please - new to UNIX. Am trying to write a script that does several things but am having trouble with this section: I have a directory and files listed on the command line (i.e. runthis.sh /export/home/myhome file1 file2 )
If file1 is found, I want to display the full path on the screen. I have beent trying to use the while...do by setting $kount and checking if $kount is gt $#. That seems to work but I can not get the $2, $3, $4.... set using $"$kount". When I echo $"$kount" it displays $2 but when I use it to find the file, I get an error message. Thanks for any and all help. Bobby |
|
#2
|
|||
|
|||
|
We can not get argument parameters the manner you have tried there. We have to transfer into an array and get those variables.
$# -- will give number of argument variables $* -- will give all argument variables $@ -- will give all argument variables and equivalent to "$*" see man ksh for this. We can try with an example as, #!/usr/bin/sh # Debugging mode set -x # Array transmission VAR=($*) i=0 while [[ $i -lt ${#VAR[*]} ]] do echo ${VAR[$i]} let i=i+1 done Sample execution gives as, $ sh test.sh /export/home/myhome file1 file2 + VAR=($*) + i=0 + [[ 0 -lt 3 ]] + echo /export/home/myhome /export/home/myhome + let i=i+1 + [[ 1 -lt 3 ]] + echo file1 file1 + let i=i+1 + [[ 2 -lt 3 ]] + echo file2 file2 + let i=i+1 + [[ 3 -lt 3 ]] VAR[0] -- will be with /export/home/myhome VAR[1] -- with file1 VAR[2] -- with file2 HTH. REgards, Muthukumar. |
|
#3
|
|||
|
|||
|
try something like:
Code:
#!/bin/sh
PWD=`pwd`
for file in $*
do [ -f $file ] || continue
case $file in /*) echo $file
;; ../*) echo `dirname $PWD`$file| sed 's/\.\.//'
;; ./*) echo $file | sed "s/^\./$PWD/"
;; *) echo $PWD/$file
;; esac
done
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Shell Scripting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|