Bash Onliner ...
Bash Onliner ...
(OP)
Greetings All,
I hope that someone can help me here. I have the following script where I would like to have the output on a single line.
below is my script that I would hope to do.
# # # # # # # # #
#!/bin/bash
#set -x
STARTHOME=$(date +%s)
sleep 60
ENDHOME=$(date +%s)
echo "HOME Time :" $((ENDHOME-STARTHOME)) | awk '{print int($1/60)":"int($1%60)}'
echo ""
echo "# This should appear in two lines"
echo "HOME Time :"
echo $((ENDHOME-STARTHOME)) | awk '{print int($1/60)":"int($1%60)}'
# # # # # # # # #
Below is what I see in the output.
The output that I would like to see is as follows.
llamprec@ICANWeb:~$ ./test.sh
# This should appear in a single line.
0:0
# This should appear in two lines
HOME Time :
1:0
I have also tried to delete the carriage return on the first line "Home Time :", but this did not work either.
Can someone please point me into the right direction as to how can I get the output on a single line.
Thanks in advance
Lawrence
I hope that someone can help me here. I have the following script where I would like to have the output on a single line.
below is my script that I would hope to do.
# # # # # # # # #
#!/bin/bash
#set -x
STARTHOME=$(date +%s)
sleep 60
ENDHOME=$(date +%s)
echo "HOME Time :" $((ENDHOME-STARTHOME)) | awk '{print int($1/60)":"int($1%60)}'
echo ""
echo "# This should appear in two lines"
echo "HOME Time :"
echo $((ENDHOME-STARTHOME)) | awk '{print int($1/60)":"int($1%60)}'
# # # # # # # # #
Below is what I see in the output.
The output that I would like to see is as follows.
llamprec@ICANWeb:~$ ./test.sh
# This should appear in a single line.
0:0
# This should appear in two lines
HOME Time :
1:0
I have also tried to delete the carriage return on the first line "Home Time :", but this did not work either.
Can someone please point me into the right direction as to how can I get the output on a single line.
Thanks in advance
Lawrence
RE: Bash Onliner ...
As you explicitly mentioned Bash, then there is a dedicated -n switch :
CODE --> Bash ( fragment )
See help echo command for details :
In other shells the solution is to add a training \c to the string. That works in latest Bash versions, too, though you have to make sure escape sequences are interpreted :
CODE --> Bash ( fragment )
As a portable solution used to be suggested to use printf instead :
CODE --> shell ( fragment )
Note that printf could also help formatting that time nicer by padding it with 0's :
CODE --> shell ( fragment )
Feherke.
feherke.github.io
RE: Bash Onliner ...
Lawrence