I want to take the absolute of a number by the following code in bash:
#!/bin/bash
echo \"Enter the first file name: \"
read first
echo \"Enter the second f
A workaround: try to eliminate the minus sign.
x=-12
x=$( sed "s/-//" <<< $x )
echo $x
12
x=-12
[[ ${x:0:1} = '-' ]] && x=${x:1} || :
echo $x
12
This syntax is a ternary opeartor. The colon ':' is the do-nothing instruction.
x=-12
echo ${x/-/}
12
Personally, scripting bash appears easier to me when I think string-first.