So I have a shell script math.sh
which takes a number as an argument and echos one added to it and one subtracted from it:
#!/bin/bash
echo "Add: "$(($1 + 1))
echo "Subtract : "$(($1 - 1))
and my other shell script execute.sh
is basically taking math.sh and a textfile as an argument and writing the output of math.sh to the text file.
#! /bin/sh
echo $1 > $2
However, the two echos are outputting to the text file on the same line as:
Add: $(($1 ++))
Subtract : $(($1 --))
when I need it on separate lines like:
Add:$(($1 ++))
Subtract:$(($1 --))
How would I do this without editing math.sh? Because my execute.sh needs to be able to output any shell script to the text file, not just math.sh, on separate lines.
math.sh
script has errors in it (you can't change$1
with++
and--
). Do you want your other script to takemath.sh
as its first argument, run it, and write the result to the second argument? If so, what about the argument thatmath.sh
takes? – Kusalananda Apr 20 '21 at 07:51echo $foo
in effect changes all runs of whitespace in$foo
to single spaces. Plus expands globs. – ilkkachu Apr 20 '21 at 09:00