Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting a directory name up with Awk 1

Status
Not open for further replies.

dendenners

Programmer
Jul 17, 2001
110
IE
Hi there,
I have a shell script that takes in a directory name as an argument (e.g. /usr/locl/bin ). The script must check if each individual directory in the argument exists, and if not, it creates it. I was wondering how to get awk to return the left-most directory to 1 variable, (in the above example /usr) and also return the rest of the directory argument to a second variable (in the above example locl/bin) so that I can recurse through the entire argument. Any help would be greatly appreciated.
 
Not sure I fully understand your question. Say you want to create the directory structure /dir1/dir2/dir3, and none of those directories exist. The best way to do this is to use mkdir with the -p switch

mkdir -p /dir1/dir2/dir3

This will create all non-existing directories down the path if they don't already exist.

Does this help?

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top