Você deve fazer:
COLUMNS=$COLUMNS my_script
Você também pode fazer algo como isso reescrever em 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/((; *[^ ;]* )[= ]*)?([^;])/\/g' \
-e's/; *([^ ;]+) ([^;]*)/\n=/g' \
-e's/;* *$//;t' -e\} \
-e'H;$!d;x;s/[[:space:]]+/,/g' \
-e's/^,*/FLAGS=/;s/,*$//')
Na minha máquina (neste terminal) que coloca o seguinte valor em $STTY
:
speed=COLUMNS=$COLUMNS my_script
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/((; *[^ ;]* )[= ]*)?([^;])/\/g' \
-e's/; *([^ ;]+) ([^;]*)/\n=/g' \
-e's/;* *$//;t' -e\} \
-e'H;$!d;x;s/[[:space:]]+/,/g' \
-e's/^,*/FLAGS=/;s/,*$//')
\ \b\a\u\d
rows=
columns=speed=%pre%%pre%\ \b\a\u\d
rows=
columns=%pre%
line=%pre%
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=
time=%pre%
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
line=%pre%
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=
time=%pre%
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
... o que deve ser bastante seguro para eval
, mas pode ser um pouco exagerado.