Quantcast
Channel: Can command substitution be nested in variable substitution? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 6

Can command substitution be nested in variable substitution?

$
0
0

I would like to use variable substitution on a particular string that I access via a command. For example, if I copy something into my clipboard, I can access it like this.

$ xclip -o -selection clipboardHere's a string I just copied.

If I assign it to a variable, then I can do variable substitution on it.

$ var=$(xclip -o -selection clipboard)$ echo $varHere's a string I just copied.$ echo ${var/copi/knott}Here's a string I just knotted.

However, is there a way to do variable substitution without assigning it to a variable? Conceptually, something like this.

$ echo ${$(xclip -o -selection clipboard)/copi/knott}bash: ${$(xclip -o -selection clipboard)/copi/knott}: bad substitution

This syntax fails, because var should be a variable name, not a string.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>