footyapps27
footyapps27

Reputation: 4042

Current Directory in Shell Script

I am quite new to shell scripting.

I am trying to make a directory when a user runs my script using bash scriptName.sh.

At present my shell script looks like,

mkdir -p build/iphoneos/XXXXXXXXXX.txt

I want to know how I can put the current directory's name in place of XXXXXXX, in the script.

Any help will be appreciated.

Upvotes: 1

Views: 206

Answers (2)

michas
michas

Reputation: 26555

You could use:

mkdir -p build/iphoneos/$(basename $PWD).txt

or

mkdir -p build/iphoneos/${PWD##*/}.txt

The first calls the basename binary. The second one removes all character up to the last / character.

Upvotes: 1

Dheerendra
Dheerendra

Reputation: 1568

Use pwd and parse get the last word.

Here is a way

foo=`pwd | rev | cut -f1 -d'/' | rev` 

then use $foo instead of XXXXX

Upvotes: 0

Related Questions