Bash command substitution not working as expected
Posted
by
Joe Fruchey
on Super User
See other posts from Super User
or by Joe Fruchey
Published on 2013-06-24T12:37:48Z
Indexed on
2013/06/25
4:24 UTC
Read the original article
Hit count: 372
I'd like to view the last few lines of a file, but I want the columns aligned. Basically, I want to disable wordwrap.
This is straightforward with:
tail $FILE | cut -c -80
But I'm trying to generalize my script for other users, and I'd like to cut to the actual terminal width, which I can get with:
stty size | cut -d" " -f2
So I would imagine that I could just
tail $FILE | cut -c -`stty size | cut -d" " -f2`
but it doesn't work:
stty: standard input: Invalid argument
cut: invalid range with no endpoint: -
Try `cut --help' for more information.
(Same results with the 'new' $() expansion.)
Now, if I echo it, it seems fine:
echo cut -c -`stty size | cut -d" " -f2`
cut -c -103
Am I just missing an escape char? Or is this somehow just not possible?
Thanks.
© Super User or respective owner