Sample Header Ad - 728x90

Cut command stored in variable will not work

4 votes
1 answer
915 views
Can someone explain why I cannot store the cut command in a variable??
user:~$ echo "foo bii doo" | cut -d ' ' -f 2
bii # as expected
# now put cut command into a variable:
user:~$ c="cut -d ' ' -f 2"
user:~$ echo "foo bii doo" | $c
cut: "'": No such file or directory
user:~$ c="cut -d \  -f 2"
user:~$ echo "foo bii doo" | $c
foo bii doo
It is not a general quoting problem because tr works:
user:~$ t="tr -d 'oo'"
user:~$ echo "foo bii doo" | $t
f bii d
(I am on Debian 12 using bash) Solved the problem in other ways already. I ask just to know why I wasted 3 hours debugging :)
Asked by archygriswald (105 rep)
Nov 26, 2023, 11:48 AM
Last activity: Nov 26, 2023, 01:20 PM