Next command output on the same line? Bash scriptSet bash script output to the line that called bash scriptprint the output of 2 commands in 1 file on the same lineBash: How do I make a command line call a script and pass two strings?How use an if statement to change the output messagereformatting command output within bash scriptBash print current line, line's output, and linebreak to filegrep script - output lines at the same time into echofind command not giving any outputvariable content is different than the output of the assigned commandHow to get du -ksh working without a carriage return in shell-scripting?
How did the SysRq key get onto modern keyboards if it's rarely used?
If you inherit a Roth 401(k), is it taxed?
My employer is refusing to give me the pay that was advertised after an internal job move
Golden Guardian removed before death related trigger
What language is Raven using for her attack in the new 52?
Is SecureRandom.ints() secure?
Would people understand me speaking German all over Europe?
Should I let a company know I've reverse engineered and rebuilt their app?
Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?
Exploiting the delay when a festival ticket is scanned
Can you ask a bank to delete all your personal info they might still have from any closed accounts?
Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?
Nuclear breeder/reactor plant controlled by two A.I. makes too much power
Why tantalum for the Hayabusa bullets?
How to store my pliers and wire cutters on my desk?
Blank spaces in a font
Can a US President, after impeachment and removal, be re-elected or re-appointed?
Should I accept an invitation to give a talk from someone who might review my proposal?
Is it okay for me to decline a project on ethical grounds?
How well would the Moon protect the Earth from an Asteroid?
Why would anyone ever invest in a cash-only etf?
Does dual boot harm a laptop battery or reduce its life?
Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?
Why did Windows 95 crash the whole system but newer Windows only crashed programs?
Next command output on the same line? Bash script
Set bash script output to the line that called bash scriptprint the output of 2 commands in 1 file on the same lineBash: How do I make a command line call a script and pass two strings?How use an if statement to change the output messagereformatting command output within bash scriptBash print current line, line's output, and linebreak to filegrep script - output lines at the same time into echofind command not giving any outputvariable content is different than the output of the assigned commandHow to get du -ksh working without a carriage return in shell-scripting?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have the following simple script:
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'
The output is something like this:
-------------------------- SOA --------------------------------
---------> 2019072905
Now my question is can I make an "echo" command after the dig and the output to be something like this:
-------------------------- SOA -----------------------------
---------> 2019072905 <-------------
I have tried to search for similar cases but was not able to find any related.
Would this be possible?
Thanks in advance.
bash shell-script echo output
add a comment |
I have the following simple script:
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'
The output is something like this:
-------------------------- SOA --------------------------------
---------> 2019072905
Now my question is can I make an "echo" command after the dig and the output to be something like this:
-------------------------- SOA -----------------------------
---------> 2019072905 <-------------
I have tried to search for similar cases but was not able to find any related.
Would this be possible?
Thanks in advance.
bash shell-script echo output
add a comment |
I have the following simple script:
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'
The output is something like this:
-------------------------- SOA --------------------------------
---------> 2019072905
Now my question is can I make an "echo" command after the dig and the output to be something like this:
-------------------------- SOA -----------------------------
---------> 2019072905 <-------------
I have tried to search for similar cases but was not able to find any related.
Would this be possible?
Thanks in advance.
bash shell-script echo output
I have the following simple script:
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'
The output is something like this:
-------------------------- SOA --------------------------------
---------> 2019072905
Now my question is can I make an "echo" command after the dig and the output to be something like this:
-------------------------- SOA -----------------------------
---------> 2019072905 <-------------
I have tried to search for similar cases but was not able to find any related.
Would this be possible?
Thanks in advance.
bash shell-script echo output
bash shell-script echo output
asked 11 hours ago
MiroMiro
273 bronze badges
273 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
I would do the whole thing in printf instead:
#!/bin/sh
header='-------------------------- SOA --------------------------'
headerLength=$(awk 'print length()' <<<"$header")
value=$(dig soa "$1" +short | awk 'print $3')
valueString="-----------> $value <-------------"
valueLength=$(awk 'print length()' <<<"$valueString")
offset=$(((headerLength + valueLength)/2+1))
printf "%snn%$offsetsn" "$header" "$valueString"
This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):
$ foo.sh 2019072905
-------------------------- SOA --------------------------------
-----------> 2019072905 <-------------
$ foo.sh "some random long string"
-------------------------- SOA --------------------------------
-----------> some random long string <-------------
$ foo.sh "foo"
-------------------------- SOA --------------------------
-----------> foo <-------------
Thanks for your advice. Will check this out with 'printf' also.
– Miro
10 hours ago
add a comment |
#!/bin/sh
soa=$(dig soa "$1" +short | awk 'print $3')
cat <<__EOF__
-------------------------- SOA -----------------------------
---------> $soa <-------------
__EOF__
BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.
I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.
Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.
– Miro
10 hours ago
that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output ofdig ... |awk ...with the echo statement just irked me. it's bad coding style and it's teaching bad habits.
– cas
10 hours ago
add a comment |
cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> ";echo $cmd
Thanks. This is indeed something that I was looking for.
– Miro
10 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f532938%2fnext-command-output-on-the-same-line-bash-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would do the whole thing in printf instead:
#!/bin/sh
header='-------------------------- SOA --------------------------'
headerLength=$(awk 'print length()' <<<"$header")
value=$(dig soa "$1" +short | awk 'print $3')
valueString="-----------> $value <-------------"
valueLength=$(awk 'print length()' <<<"$valueString")
offset=$(((headerLength + valueLength)/2+1))
printf "%snn%$offsetsn" "$header" "$valueString"
This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):
$ foo.sh 2019072905
-------------------------- SOA --------------------------------
-----------> 2019072905 <-------------
$ foo.sh "some random long string"
-------------------------- SOA --------------------------------
-----------> some random long string <-------------
$ foo.sh "foo"
-------------------------- SOA --------------------------
-----------> foo <-------------
Thanks for your advice. Will check this out with 'printf' also.
– Miro
10 hours ago
add a comment |
I would do the whole thing in printf instead:
#!/bin/sh
header='-------------------------- SOA --------------------------'
headerLength=$(awk 'print length()' <<<"$header")
value=$(dig soa "$1" +short | awk 'print $3')
valueString="-----------> $value <-------------"
valueLength=$(awk 'print length()' <<<"$valueString")
offset=$(((headerLength + valueLength)/2+1))
printf "%snn%$offsetsn" "$header" "$valueString"
This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):
$ foo.sh 2019072905
-------------------------- SOA --------------------------------
-----------> 2019072905 <-------------
$ foo.sh "some random long string"
-------------------------- SOA --------------------------------
-----------> some random long string <-------------
$ foo.sh "foo"
-------------------------- SOA --------------------------
-----------> foo <-------------
Thanks for your advice. Will check this out with 'printf' also.
– Miro
10 hours ago
add a comment |
I would do the whole thing in printf instead:
#!/bin/sh
header='-------------------------- SOA --------------------------'
headerLength=$(awk 'print length()' <<<"$header")
value=$(dig soa "$1" +short | awk 'print $3')
valueString="-----------> $value <-------------"
valueLength=$(awk 'print length()' <<<"$valueString")
offset=$(((headerLength + valueLength)/2+1))
printf "%snn%$offsetsn" "$header" "$valueString"
This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):
$ foo.sh 2019072905
-------------------------- SOA --------------------------------
-----------> 2019072905 <-------------
$ foo.sh "some random long string"
-------------------------- SOA --------------------------------
-----------> some random long string <-------------
$ foo.sh "foo"
-------------------------- SOA --------------------------
-----------> foo <-------------
I would do the whole thing in printf instead:
#!/bin/sh
header='-------------------------- SOA --------------------------'
headerLength=$(awk 'print length()' <<<"$header")
value=$(dig soa "$1" +short | awk 'print $3')
valueString="-----------> $value <-------------"
valueLength=$(awk 'print length()' <<<"$valueString")
offset=$(((headerLength + valueLength)/2+1))
printf "%snn%$offsetsn" "$header" "$valueString"
This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):
$ foo.sh 2019072905
-------------------------- SOA --------------------------------
-----------> 2019072905 <-------------
$ foo.sh "some random long string"
-------------------------- SOA --------------------------------
-----------> some random long string <-------------
$ foo.sh "foo"
-------------------------- SOA --------------------------
-----------> foo <-------------
answered 10 hours ago
terdon♦terdon
139k33 gold badges286 silver badges463 bronze badges
139k33 gold badges286 silver badges463 bronze badges
Thanks for your advice. Will check this out with 'printf' also.
– Miro
10 hours ago
add a comment |
Thanks for your advice. Will check this out with 'printf' also.
– Miro
10 hours ago
Thanks for your advice. Will check this out with 'printf' also.
– Miro
10 hours ago
Thanks for your advice. Will check this out with 'printf' also.
– Miro
10 hours ago
add a comment |
#!/bin/sh
soa=$(dig soa "$1" +short | awk 'print $3')
cat <<__EOF__
-------------------------- SOA -----------------------------
---------> $soa <-------------
__EOF__
BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.
I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.
Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.
– Miro
10 hours ago
that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output ofdig ... |awk ...with the echo statement just irked me. it's bad coding style and it's teaching bad habits.
– cas
10 hours ago
add a comment |
#!/bin/sh
soa=$(dig soa "$1" +short | awk 'print $3')
cat <<__EOF__
-------------------------- SOA -----------------------------
---------> $soa <-------------
__EOF__
BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.
I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.
Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.
– Miro
10 hours ago
that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output ofdig ... |awk ...with the echo statement just irked me. it's bad coding style and it's teaching bad habits.
– cas
10 hours ago
add a comment |
#!/bin/sh
soa=$(dig soa "$1" +short | awk 'print $3')
cat <<__EOF__
-------------------------- SOA -----------------------------
---------> $soa <-------------
__EOF__
BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.
I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.
#!/bin/sh
soa=$(dig soa "$1" +short | awk 'print $3')
cat <<__EOF__
-------------------------- SOA -----------------------------
---------> $soa <-------------
__EOF__
BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.
I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.
edited 10 hours ago
answered 11 hours ago
cascas
40.9k4 gold badges58 silver badges109 bronze badges
40.9k4 gold badges58 silver badges109 bronze badges
Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.
– Miro
10 hours ago
that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output ofdig ... |awk ...with the echo statement just irked me. it's bad coding style and it's teaching bad habits.
– cas
10 hours ago
add a comment |
Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.
– Miro
10 hours ago
that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output ofdig ... |awk ...with the echo statement just irked me. it's bad coding style and it's teaching bad habits.
– cas
10 hours ago
Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.
– Miro
10 hours ago
Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.
– Miro
10 hours ago
that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of
dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.– cas
10 hours ago
that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of
dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.– cas
10 hours ago
add a comment |
cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> ";echo $cmd
Thanks. This is indeed something that I was looking for.
– Miro
10 hours ago
add a comment |
cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> ";echo $cmd
Thanks. This is indeed something that I was looking for.
– Miro
10 hours ago
add a comment |
cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> ";echo $cmd
cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)
echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> ";echo $cmd
answered 11 hours ago
Rasool ZiafatyRasool Ziafaty
1149 bronze badges
1149 bronze badges
Thanks. This is indeed something that I was looking for.
– Miro
10 hours ago
add a comment |
Thanks. This is indeed something that I was looking for.
– Miro
10 hours ago
Thanks. This is indeed something that I was looking for.
– Miro
10 hours ago
Thanks. This is indeed something that I was looking for.
– Miro
10 hours ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f532938%2fnext-command-output-on-the-same-line-bash-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown