Solved

shell arg parsing

Posted on 1997-02-20
1
603 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 58
sum67 challenge 35 89
sum28 challenge 31 96
My project did see openJDK that I installed. What could be the problem 7 95
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now