[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

shell arg parsing

I need a way to seperate an argument of a shell script,
and assign them to env variables.
Example: > foo /home2/users/tom/filelist
In this case i would want to isolate into a variable the
"home2" portion of the path argument.

On a related subject, Is there another method
to determine if a unix file path argument to a shell
script is a local file system or a nfs mounted filesystem?

Typically, i'm using sh scripts.
Thanks
Jon Keller
0
j_k
Asked:
j_k
1 Solution
 
pc012197Commented:
Question 1:
The following line will assign the first element of the pathname given as the first argument of your sh-script to the variable 'var'.

var=`echo $1|sed 's=^/==;s=/.*$==;'`

Question 2:

# this gives you the mount point of $1
mp=`df $1|awk '{print $1}'|tail -1`
# if the mount point contains a colon, it's an NFS mount
if [ `echo $mp|grep -c ':'` -eq 1 ]; then
# NFS mounted
else
# no NFS
fi

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now