/bin/sh: 1: Syntax error: Unterminated quoted string when using basename

code example:my PWD = /aa/bb/cc/dd

dir= `dirname "$(PWD)"`
output = `basename "${dir}"`

dir variable outputs correctly: /aa/bb/cc

desired output variable: cc

error I'm getting: /bin/sh: 1: Syntax error: Unterminated quoted string

I've tried different quotation combinations and other things like these suggested solutions: and

4

2 Answers

Below code is working for me :

dir1=`dirname "$PWD"`
output=`basename "$dir1"`
1

Instead of "$(PWD)", you'll want "${PWD}". The former tries to execute the command PWD, the latter expands to the value of the variable PWD.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like