deppfx
deppfx

Reputation: 751

Why can't I extract the last three characters of my hostname using the below shell parameter expansion?

deppfx@localhost:/tmp$ echo ${$(hostname): -3}

-bash: ${$(hostname): -3}: bad substitution

I am looking for the output as ost.

Related: https://stackoverflow.com/a/19858692/598175

Upvotes: 0

Views: 180

Answers (2)

blashser
blashser

Reputation: 1031

The substitution works in variables, not in commands.

echo $(myVar=$(hostname);echo ${myVar: -3})

Upvotes: 1

Mahesh Kharvi
Mahesh Kharvi

Reputation: 399

It should be ${variable: -3}. Don't try to substitute command.

Upvotes: 2

Related Questions