how to keep line feed in result returned by bash command
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
let's say, I can rsh to machine XXX as user foo, then after executing:
$result=$(rsh -l foo XXX "ls");
echo $result;
I found that the line feed is removed in the result, and I can't see the result in a line by line way. so what I should do if I'd like to have the line feed int the returned result?
bash
add a comment |
let's say, I can rsh to machine XXX as user foo, then after executing:
$result=$(rsh -l foo XXX "ls");
echo $result;
I found that the line feed is removed in the result, and I can't see the result in a line by line way. so what I should do if I'd like to have the line feed int the returned result?
bash
You should not have a dollar sign in front of the varible name when you assign to it.rsh=$(rsh -l foo XXX "ls")
. The terminating semicolons are redundant but harmless.
– tripleee
Mar 12 '12 at 8:05
add a comment |
let's say, I can rsh to machine XXX as user foo, then after executing:
$result=$(rsh -l foo XXX "ls");
echo $result;
I found that the line feed is removed in the result, and I can't see the result in a line by line way. so what I should do if I'd like to have the line feed int the returned result?
bash
let's say, I can rsh to machine XXX as user foo, then after executing:
$result=$(rsh -l foo XXX "ls");
echo $result;
I found that the line feed is removed in the result, and I can't see the result in a line by line way. so what I should do if I'd like to have the line feed int the returned result?
bash
bash
asked Mar 12 '12 at 7:27
HaiYuan ZhangHaiYuan Zhang
1,51952332
1,51952332
You should not have a dollar sign in front of the varible name when you assign to it.rsh=$(rsh -l foo XXX "ls")
. The terminating semicolons are redundant but harmless.
– tripleee
Mar 12 '12 at 8:05
add a comment |
You should not have a dollar sign in front of the varible name when you assign to it.rsh=$(rsh -l foo XXX "ls")
. The terminating semicolons are redundant but harmless.
– tripleee
Mar 12 '12 at 8:05
You should not have a dollar sign in front of the varible name when you assign to it.
rsh=$(rsh -l foo XXX "ls")
. The terminating semicolons are redundant but harmless.– tripleee
Mar 12 '12 at 8:05
You should not have a dollar sign in front of the varible name when you assign to it.
rsh=$(rsh -l foo XXX "ls")
. The terminating semicolons are redundant but harmless.– tripleee
Mar 12 '12 at 8:05
add a comment |
2 Answers
2
active
oldest
votes
The newline is there; the error is in using echo
to examine it (without double quotes around the variable, too!)
result=$(rsh -l foo XXX "ls")
echo "$result"
In trivial cases, you can get away without quotes, but the interesting cases might even contain security issues.
If you are only capturing the standard output of rsh
so that you can print it to standard output yourself, this is a useless use of echo
Probably also preferssh
overrsh
and don't usels
in scripts.
– tripleee
Jan 30 at 11:33
add a comment |
Edit: If you mean the newlines between each file, just make sure to quote the result:
result="$(rsh -l foo XXX "ls");"
This will keep any characters except NUL ($''
), which can't be stored in a Bash variable.
If you mean that the trailing newline is lost, then this is the simplest solution I know:
resultx="$(commands...; echo x)"
result="${resultx%x}"
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f399685%2fhow-to-keep-line-feed-in-result-returned-by-bash-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The newline is there; the error is in using echo
to examine it (without double quotes around the variable, too!)
result=$(rsh -l foo XXX "ls")
echo "$result"
In trivial cases, you can get away without quotes, but the interesting cases might even contain security issues.
If you are only capturing the standard output of rsh
so that you can print it to standard output yourself, this is a useless use of echo
Probably also preferssh
overrsh
and don't usels
in scripts.
– tripleee
Jan 30 at 11:33
add a comment |
The newline is there; the error is in using echo
to examine it (without double quotes around the variable, too!)
result=$(rsh -l foo XXX "ls")
echo "$result"
In trivial cases, you can get away without quotes, but the interesting cases might even contain security issues.
If you are only capturing the standard output of rsh
so that you can print it to standard output yourself, this is a useless use of echo
Probably also preferssh
overrsh
and don't usels
in scripts.
– tripleee
Jan 30 at 11:33
add a comment |
The newline is there; the error is in using echo
to examine it (without double quotes around the variable, too!)
result=$(rsh -l foo XXX "ls")
echo "$result"
In trivial cases, you can get away without quotes, but the interesting cases might even contain security issues.
If you are only capturing the standard output of rsh
so that you can print it to standard output yourself, this is a useless use of echo
The newline is there; the error is in using echo
to examine it (without double quotes around the variable, too!)
result=$(rsh -l foo XXX "ls")
echo "$result"
In trivial cases, you can get away without quotes, but the interesting cases might even contain security issues.
If you are only capturing the standard output of rsh
so that you can print it to standard output yourself, this is a useless use of echo
edited Jan 30 at 6:23
answered Mar 12 '12 at 8:04
tripleeetripleee
1,88932130
1,88932130
Probably also preferssh
overrsh
and don't usels
in scripts.
– tripleee
Jan 30 at 11:33
add a comment |
Probably also preferssh
overrsh
and don't usels
in scripts.
– tripleee
Jan 30 at 11:33
Probably also prefer
ssh
over rsh
and don't use ls
in scripts.– tripleee
Jan 30 at 11:33
Probably also prefer
ssh
over rsh
and don't use ls
in scripts.– tripleee
Jan 30 at 11:33
add a comment |
Edit: If you mean the newlines between each file, just make sure to quote the result:
result="$(rsh -l foo XXX "ls");"
This will keep any characters except NUL ($''
), which can't be stored in a Bash variable.
If you mean that the trailing newline is lost, then this is the simplest solution I know:
resultx="$(commands...; echo x)"
result="${resultx%x}"
add a comment |
Edit: If you mean the newlines between each file, just make sure to quote the result:
result="$(rsh -l foo XXX "ls");"
This will keep any characters except NUL ($''
), which can't be stored in a Bash variable.
If you mean that the trailing newline is lost, then this is the simplest solution I know:
resultx="$(commands...; echo x)"
result="${resultx%x}"
add a comment |
Edit: If you mean the newlines between each file, just make sure to quote the result:
result="$(rsh -l foo XXX "ls");"
This will keep any characters except NUL ($''
), which can't be stored in a Bash variable.
If you mean that the trailing newline is lost, then this is the simplest solution I know:
resultx="$(commands...; echo x)"
result="${resultx%x}"
Edit: If you mean the newlines between each file, just make sure to quote the result:
result="$(rsh -l foo XXX "ls");"
This will keep any characters except NUL ($''
), which can't be stored in a Bash variable.
If you mean that the trailing newline is lost, then this is the simplest solution I know:
resultx="$(commands...; echo x)"
result="${resultx%x}"
edited Mar 12 '12 at 10:04
answered Mar 12 '12 at 9:50
l0b0l0b0
5,53832441
5,53832441
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f399685%2fhow-to-keep-line-feed-in-result-returned-by-bash-command%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
You should not have a dollar sign in front of the varible name when you assign to it.
rsh=$(rsh -l foo XXX "ls")
. The terminating semicolons are redundant but harmless.– tripleee
Mar 12 '12 at 8:05