Punkster
Punkster

Reputation: 221

Delete a part of variable and assign value to another variable in Shell Script

I have a shell script variable as follows

a='\bin\tem\abc\xyz.sh'

I must remove the xyz.sh from the path and need to store it in a another variable called b. That is b must contain '\bin\tem\abc\'.

Upvotes: 0

Views: 46

Answers (1)

John B
John B

Reputation: 3646

You can use Parameter Expansion:

b="${a%\\*}\\"

This removes the trailing \ and everything after it before appending with \.

Upvotes: 1

Related Questions