czchlong
czchlong

Reputation: 2574

Parsing arguments from command line for shell script

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.

Upvotes: 2

Views: 491

Answers (2)

thiton
thiton

Reputation: 36049

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

THEDIR=`basename "$1"`

should do the trick.

Upvotes: 3

clarkb86
clarkb86

Reputation: 693

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

Upvotes: 0

Related Questions