[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

shell arg parsing

Posted on 1997-02-20
1
Medium Priority
?
625 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 100 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

656 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