Solved

shell arg parsing

Posted on 1997-02-20
1
614 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
[X]
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
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
Question regarding Copy/Paste 16 98
Generic progress indicator 6 119
deburging in oracle form 12 112
how to split multiple lines delimiter : 8 120
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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