I have an application which outputs a string with a number, like this:
output number is 20.
I have a code which parses output and cutting out only the number:
result=$(./my_script | awk 'print $4')
echo $result
the result output will be "20" as expected, but now, if I would try to use it as an integer, for example:
result=$((result+1))
then I will get an error:
13915: syntax error: operand expected (error token is "20")
Using it as a seq argument will also give an error
$(seq 0 $result)
seq: invalid floating point argument: ‘\033[?25h\033[?0c20’
trying to print it with %q will give the same result:
printf '%q' $result
'\E[?25h\E[?0c20'
So, it looks like there are some unexpected characters in the string, but I'm not sure how to trim them?
Thank you!
[ -t 1 ]for stdout,[ -t 2 ]for stderr; in C, the call isisatty()). This program is buggy, and you should report those bugs to its author.ssh -Tto explicitly disable TTY emulation on SSH's part. BTW,echo $resultintroduces some bugs in and of itself, like replacing a*in the output with a list of files. Better to useecho "$result", or -- to remove everything but numbers --echo "${result//[^[:digit:]]/}"... or just to avoid the command substitution altogether and let the pipeline write direct to stdout.