UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 8th, 2004, 05:00 PM
BobbyG BobbyG is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 BobbyG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 9th, 2004, 12:21 AM
Muthukumar_K Muthukumar_K is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 13 Muthukumar_K User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Muthukumar_K
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.

Reply With Quote
  #3  
Old October 10th, 2004, 04:07 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Shell Scripting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway