I have a shell script with this code:
var=`hg st -R \"$path\"`
if [ -n \"$var\" ]; then
echo $var
fi
But the conditional code always ex
Python has a function strip()
that works identically to PHP's trim()
, so we can just do a little inline Python to make an easily understandable utility for this:
alias trim='python -c "import sys; sys.stdout.write(sys.stdin.read().strip())"'
This will trim leading and trailing whitespace (including newlines).
$ x=`echo -e "\n\t \n" | trim`
$ if [ -z "$x" ]; then echo hi; fi
hi