Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

shell arg parsing

Posted on 1997-02-20
1
611 Views
Last Modified: 2013-12-26
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
Comment
Question by:j_k
1 Comment
 
LVL 3

Accepted Solution

by:
pc012197 earned 50 total points
ID: 1292266
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question