Reputation: 31485
I'm trying to do a substring on bash and I'm following this Bash scripting cheat sheet.
echo $(pwd)
> Successfully outputs the current working DIR
What am I doing wrong?
I'm trying to slice the $(pwd)
at the index 2. I know it's possible to omit the length, to return the rest of the string from that position.
So I'm doing this, and I'm getting the bad substitution
error.
echo ${$(pwd):2}
> bash: ${$(pwd):2}: bad substitution
Upvotes: 1
Views: 844
Reputation: 12895
You are getting confused between command substitution with parameter substitution.
In your particular situation you will need to read the command substitution of pwd into a variable first and then use that for parameter expansion and so:
pworkd=$(pwd)
echo ${$(pworkd):2}
Upvotes: 2