2

I am still a junior with the linux shell script and would like help with a certain script.

I would run a sample shell script such as the following from the command line that takes in a directory as an argument:

./script.sh /some_dir/some_exe

How can I parse out the "some_dir" in my shell script?

Thanks.

2 Answers 2

3

The dirname command extracts the directory name from a string; so

THEDIR=`basename "$1"`

should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using Bash, it should be stored in $1. I'm pretty sure it's the same for other shells.

1 Comment

Oh crap, sorry, I missed the part where you just wanted the dir of the parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.