You should do:
COLUMNS=$COLUMNS my_script
You could also do something like this rewrite in sed
:
STTY=
for fd in 0 1 2
do [ -t "$fd" ] &&
break
done|| ${STTY:?Run "$0" on a terminal}
STTY=$( stty -a <&"$fd" |
sed -Ee'/;/{s/^/;/' \
-e's/((; *[^ ;]* )[= ]*)?([^;])/\2\\\3/g' \
-e's/; *([^ ;]+) ([^;]*)/\n\1=\2/g' \
-e's/;* *$//;t' -e\} \
-e'H;$!d;x;s/[[:space:]]+/,/g' \
-e's/^,*/FLAGS=/;s/,*$//')
On my machine (on this terminal) that puts the following value in $STTY
:
speed=\3\8\4\0\0\ \b\a\u\d
rows=\4\3
columns=\1\0\9
line=\0
intr=\^\C
quit=\^\\
erase=\^\H
kill=\^\U
eof=\^\D
eol=\<\u\n\d\e\f\>
eol2=\<\u\n\d\e\f\>
swtch=\<\u\n\d\e\f\>
start=\^\Q
stop=\^\S
susp=\^\Z
rprnt=\^\R
werase=\^\W
lnext=\^\V
discard=\^\O
min=\1
time=\0
FLAGS=-parenb,-parodd,-cmspar,cs8,-hupcl,-cstopb,cread,-clocal,-crtscts,-ignbrk,-brkint,-ignpar,-parmrk,-inpck,-istrip,-inlcr,-igncr,icrnl,ixon,-ixoff,-iuclc,-ixany,-imaxbel,iutf8,opost,-olcuc,-ocrnl,onlcr,-onocr,-onlret,-ofill,-ofdel,nl0,cr0,tab0,bs0,vt0,ff0,isig,icanon,iexten,echo,echoe,echok,-echonl,-noflsh,-xcase,-tostop,-echoprt,echoctl,echoke,-extproc
...which should be plenty safe for eval
, but it may be a little over the top, though.