IFS Separator in VariablesCan IFS (Internal Field Separator) function as a single separator for multiple...
Why are there no wireless switches?
"syntax error near unexpected token" after editing .bashrc
At what point does a land become controlled?
Why does the seven segment display have decimal point at the right?
How to improvise or make pot grip / pot handle
Why did Boris Johnson call for new elections?
Is every sentence we write or utter either true or false?
Statistical closeness implies computational indistinguishability
Why do the Brexit opposition parties not want a new election?
What is the delta-v required to get a mass in Earth orbit into the sun using a SINGLE transfer?
k times Fold with 3 changing extra variables
How to interpret or parse this confusing 'NOT' and 'AND' legal clause
How can electricity be positive when electrons are negative?
What exactly is Apple Cider
Owner keeps cutting corners and poaching workers for his other company
Poor management handling of recent sickness and how to approach my return?
Entering the US with dual citizenship but US passport is long expired?
How many attacks exactly do I get combining Dual Wielder feat with Two-Weapon Fighting style?
Can the Spell Alter Self allow a Kenku to Speak Normally?
Draw the ☣ (Biohazard Symbol)
Why are UK MPs allowed to abstain (but it counts as a no)?
How can I hint that my character isn't real?
The Green Glass Door, Revisited
Relationship between speed and cadence?
IFS Separator in Variables
Can IFS (Internal Field Separator) function as a single separator for multiple consecutive delimiter chars?What is the 'IFS'?In `while IFS= read..`, why does IFS have no effect?Understanding IFSComparing variables in arithmeticAre there shells that supports typed variables and multidimensional arrays?Where are shell variables stored?How to print all non-environment variables?Listing shell variables with a fixed prefixHow to test if IFS is unset in ksh93?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
A string is passed to a shell script which should add the date and separate the words by a given character.
The script looks like this:
#!/bin/bash
SEPARATOR=';'
# change separator
ORG_IFS="$IFS"
IFS=$SEPARATOR
# todays date
TODAY=$(date +"%d.%m.%Y")
echo "date: " $TODAY
# concatenate command line arguments
DATA_STRING="$*"
echo "data: " "$DATA_STRING" "(correct)"
echo "data: " $DATA_STRING "(wrong: missing separator)"
# date + command line arguments
FINAL_STRING="${TODAY}${SEPARATOR}"${DATA_STRING}""
echo "date+data: " $FINAL_STRING
# restore original separator
IFS=$ORG_IFS
A call would look like this:
myscript.sh apple banana cherry
The output now is:
date: 07.09.2019
data: apple;banana;cherry (correct)
data: apple banana cherry (wrong: missing separator)
date+data: 07.09.2019 apple banana cherry
The desired result is:
07.09.2019;apple;banana;cherry
Being fairly new to Linux shell programming I do not understand how to keep the seperator when concatenating variables to a string.
I've tried a lot of combinations with and without the "..." but I don't understand what this actually does to a variable.
shell variable
New contributor
add a comment |
A string is passed to a shell script which should add the date and separate the words by a given character.
The script looks like this:
#!/bin/bash
SEPARATOR=';'
# change separator
ORG_IFS="$IFS"
IFS=$SEPARATOR
# todays date
TODAY=$(date +"%d.%m.%Y")
echo "date: " $TODAY
# concatenate command line arguments
DATA_STRING="$*"
echo "data: " "$DATA_STRING" "(correct)"
echo "data: " $DATA_STRING "(wrong: missing separator)"
# date + command line arguments
FINAL_STRING="${TODAY}${SEPARATOR}"${DATA_STRING}""
echo "date+data: " $FINAL_STRING
# restore original separator
IFS=$ORG_IFS
A call would look like this:
myscript.sh apple banana cherry
The output now is:
date: 07.09.2019
data: apple;banana;cherry (correct)
data: apple banana cherry (wrong: missing separator)
date+data: 07.09.2019 apple banana cherry
The desired result is:
07.09.2019;apple;banana;cherry
Being fairly new to Linux shell programming I do not understand how to keep the seperator when concatenating variables to a string.
I've tried a lot of combinations with and without the "..." but I don't understand what this actually does to a variable.
shell variable
New contributor
add a comment |
A string is passed to a shell script which should add the date and separate the words by a given character.
The script looks like this:
#!/bin/bash
SEPARATOR=';'
# change separator
ORG_IFS="$IFS"
IFS=$SEPARATOR
# todays date
TODAY=$(date +"%d.%m.%Y")
echo "date: " $TODAY
# concatenate command line arguments
DATA_STRING="$*"
echo "data: " "$DATA_STRING" "(correct)"
echo "data: " $DATA_STRING "(wrong: missing separator)"
# date + command line arguments
FINAL_STRING="${TODAY}${SEPARATOR}"${DATA_STRING}""
echo "date+data: " $FINAL_STRING
# restore original separator
IFS=$ORG_IFS
A call would look like this:
myscript.sh apple banana cherry
The output now is:
date: 07.09.2019
data: apple;banana;cherry (correct)
data: apple banana cherry (wrong: missing separator)
date+data: 07.09.2019 apple banana cherry
The desired result is:
07.09.2019;apple;banana;cherry
Being fairly new to Linux shell programming I do not understand how to keep the seperator when concatenating variables to a string.
I've tried a lot of combinations with and without the "..." but I don't understand what this actually does to a variable.
shell variable
New contributor
A string is passed to a shell script which should add the date and separate the words by a given character.
The script looks like this:
#!/bin/bash
SEPARATOR=';'
# change separator
ORG_IFS="$IFS"
IFS=$SEPARATOR
# todays date
TODAY=$(date +"%d.%m.%Y")
echo "date: " $TODAY
# concatenate command line arguments
DATA_STRING="$*"
echo "data: " "$DATA_STRING" "(correct)"
echo "data: " $DATA_STRING "(wrong: missing separator)"
# date + command line arguments
FINAL_STRING="${TODAY}${SEPARATOR}"${DATA_STRING}""
echo "date+data: " $FINAL_STRING
# restore original separator
IFS=$ORG_IFS
A call would look like this:
myscript.sh apple banana cherry
The output now is:
date: 07.09.2019
data: apple;banana;cherry (correct)
data: apple banana cherry (wrong: missing separator)
date+data: 07.09.2019 apple banana cherry
The desired result is:
07.09.2019;apple;banana;cherry
Being fairly new to Linux shell programming I do not understand how to keep the seperator when concatenating variables to a string.
I've tried a lot of combinations with and without the "..." but I don't understand what this actually does to a variable.
shell variable
shell variable
New contributor
New contributor
New contributor
asked 34 mins ago
SörenSören
1
1
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
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/4.0/"u003ecc by-sa 4.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
});
}
});
Sören is a new contributor. Be nice, and check out our Code of Conduct.
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%2f539455%2fifs-separator-in-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sören is a new contributor. Be nice, and check out our Code of Conduct.
Sören is a new contributor. Be nice, and check out our Code of Conduct.
Sören is a new contributor. Be nice, and check out our Code of Conduct.
Sören is a new contributor. Be nice, and check out our Code of Conduct.
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%2f539455%2fifs-separator-in-variables%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