How to prevent a command from ticks from being executed in Linux bash scripting Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionwhy is this init.d-script not being executed at system reboot?Prevent a command from being executed after another commandHow to save command line history without logout?prevent bash completion from altering underscore variable $_Command to prevent suspend while another command executes?bash on command event (or shell)How to prevent bash command substitution output from being escaped?How to prevent a directory from being editedQueue up commands while one command is being executedHow do I time a compound command executed in parallel?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
What do you call a plan that's an alternative plan in case your initial plan fails?
Why is there no army of Iron-Mans in the MCU?
What do you call the holes in a flute?
Can a monk deflect thrown melee weapons?
How to market an anarchic city as a tourism spot to people living in civilized areas?
How do I automatically answer y in bash script?
How does modal jazz use chord progressions?
Unexpected result with right shift after bitwise negation
Problem when applying foreach loop
Mortgage adviser recommends a longer term than necessary combined with overpayments
Was credit for the black hole image misattributed?
How can I make names more distinctive without making them longer?
Statistical model of ligand substitution
What's the difference between (size_t)-1 and ~0?
Working around an AWS network ACL rule limit
Who can trigger ship-wide alerts in Star Trek?
What is the largest species of polychaete?
How do you clear the ApexPages.getMessages() collection in a test?
Fishing simulator
Slither Like a Snake
How can players take actions together that are impossible otherwise?
Stop battery usage [Ubuntu 18]
How to rotate it perfectly?
How to prevent a command from ticks from being executed in Linux bash scripting
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionwhy is this init.d-script not being executed at system reboot?Prevent a command from being executed after another commandHow to save command line history without logout?prevent bash completion from altering underscore variable $_Command to prevent suspend while another command executes?bash on command event (or shell)How to prevent bash command substitution output from being escaped?How to prevent a directory from being editedQueue up commands while one command is being executedHow do I time a compound command executed in parallel?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to save in variable $COMMAND
the second tab delimited field from variable $i
, however when I do that, the command cd ~
gets executed. There is a tab character between TEST_CASE_001
and cd ~
i='TEST_CASE_001 cd ~'
COMMAND=$(echo $i | cut -f2)
How to prevent it from being executed and save it in the $COMMAND
?
linux bash scripting
add a comment |
I want to save in variable $COMMAND
the second tab delimited field from variable $i
, however when I do that, the command cd ~
gets executed. There is a tab character between TEST_CASE_001
and cd ~
i='TEST_CASE_001 cd ~'
COMMAND=$(echo $i | cut -f2)
How to prevent it from being executed and save it in the $COMMAND
?
linux bash scripting
1
I don't think your characterisation of what's happening is accurate. Could you edit in a transcript of your experiment and the result you're seeing?
– Michael Homer
Apr 10 at 22:15
add a comment |
I want to save in variable $COMMAND
the second tab delimited field from variable $i
, however when I do that, the command cd ~
gets executed. There is a tab character between TEST_CASE_001
and cd ~
i='TEST_CASE_001 cd ~'
COMMAND=$(echo $i | cut -f2)
How to prevent it from being executed and save it in the $COMMAND
?
linux bash scripting
I want to save in variable $COMMAND
the second tab delimited field from variable $i
, however when I do that, the command cd ~
gets executed. There is a tab character between TEST_CASE_001
and cd ~
i='TEST_CASE_001 cd ~'
COMMAND=$(echo $i | cut -f2)
How to prevent it from being executed and save it in the $COMMAND
?
linux bash scripting
linux bash scripting
edited Apr 10 at 22:20
Alex
asked Apr 10 at 22:09
AlexAlex
4321710
4321710
1
I don't think your characterisation of what's happening is accurate. Could you edit in a transcript of your experiment and the result you're seeing?
– Michael Homer
Apr 10 at 22:15
add a comment |
1
I don't think your characterisation of what's happening is accurate. Could you edit in a transcript of your experiment and the result you're seeing?
– Michael Homer
Apr 10 at 22:15
1
1
I don't think your characterisation of what's happening is accurate. Could you edit in a transcript of your experiment and the result you're seeing?
– Michael Homer
Apr 10 at 22:15
I don't think your characterisation of what's happening is accurate. Could you edit in a transcript of your experiment and the result you're seeing?
– Michael Homer
Apr 10 at 22:15
add a comment |
1 Answer
1
active
oldest
votes
Note: this answer is for the first version of the question.
First, let's define i
with the tab:
$ i=$'ls -ltcd ~'
Now, let's try your commands without and then with double-quotes:
$ echo $i | cut -f2
ls -l cd ~
$ echo "$i" | cut -f2
cd ~
If you want cut
to work as expected, you need to put $i
in double-quotes. Without the double-quotes, the shell performs, among other things, word splitting which results in the tab being replaced by a blank. This prevents the cut
command from working as you expect.
Doing the assignment to Command does not change this:
$ Command=$(echo $i | cut -f2); declare -p Command
declare -- Command="ls -l cd ~"
$ Command=$(echo "$i" | cut -f2); declare -p Command
declare -- Command="cd ~"
General comments
You haven't provided the larger context here but, in general, it is a bad idea to try to put commands in variables. See "I'm trying to put a command in a variable, but the complex cases always fail!".
Separately, regarding the variable COMMAND
, it is better practice to use lower or mixed case for your shell variables. The system uses upper case for its variables and you don't want to accidentally overwrite one of them.
1
Thank you for your help and comments! It works now.
– Alex
Apr 10 at 22:24
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%2f511772%2fhow-to-prevent-a-command-from-ticks-from-being-executed-in-linux-bash-scripting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Note: this answer is for the first version of the question.
First, let's define i
with the tab:
$ i=$'ls -ltcd ~'
Now, let's try your commands without and then with double-quotes:
$ echo $i | cut -f2
ls -l cd ~
$ echo "$i" | cut -f2
cd ~
If you want cut
to work as expected, you need to put $i
in double-quotes. Without the double-quotes, the shell performs, among other things, word splitting which results in the tab being replaced by a blank. This prevents the cut
command from working as you expect.
Doing the assignment to Command does not change this:
$ Command=$(echo $i | cut -f2); declare -p Command
declare -- Command="ls -l cd ~"
$ Command=$(echo "$i" | cut -f2); declare -p Command
declare -- Command="cd ~"
General comments
You haven't provided the larger context here but, in general, it is a bad idea to try to put commands in variables. See "I'm trying to put a command in a variable, but the complex cases always fail!".
Separately, regarding the variable COMMAND
, it is better practice to use lower or mixed case for your shell variables. The system uses upper case for its variables and you don't want to accidentally overwrite one of them.
1
Thank you for your help and comments! It works now.
– Alex
Apr 10 at 22:24
add a comment |
Note: this answer is for the first version of the question.
First, let's define i
with the tab:
$ i=$'ls -ltcd ~'
Now, let's try your commands without and then with double-quotes:
$ echo $i | cut -f2
ls -l cd ~
$ echo "$i" | cut -f2
cd ~
If you want cut
to work as expected, you need to put $i
in double-quotes. Without the double-quotes, the shell performs, among other things, word splitting which results in the tab being replaced by a blank. This prevents the cut
command from working as you expect.
Doing the assignment to Command does not change this:
$ Command=$(echo $i | cut -f2); declare -p Command
declare -- Command="ls -l cd ~"
$ Command=$(echo "$i" | cut -f2); declare -p Command
declare -- Command="cd ~"
General comments
You haven't provided the larger context here but, in general, it is a bad idea to try to put commands in variables. See "I'm trying to put a command in a variable, but the complex cases always fail!".
Separately, regarding the variable COMMAND
, it is better practice to use lower or mixed case for your shell variables. The system uses upper case for its variables and you don't want to accidentally overwrite one of them.
1
Thank you for your help and comments! It works now.
– Alex
Apr 10 at 22:24
add a comment |
Note: this answer is for the first version of the question.
First, let's define i
with the tab:
$ i=$'ls -ltcd ~'
Now, let's try your commands without and then with double-quotes:
$ echo $i | cut -f2
ls -l cd ~
$ echo "$i" | cut -f2
cd ~
If you want cut
to work as expected, you need to put $i
in double-quotes. Without the double-quotes, the shell performs, among other things, word splitting which results in the tab being replaced by a blank. This prevents the cut
command from working as you expect.
Doing the assignment to Command does not change this:
$ Command=$(echo $i | cut -f2); declare -p Command
declare -- Command="ls -l cd ~"
$ Command=$(echo "$i" | cut -f2); declare -p Command
declare -- Command="cd ~"
General comments
You haven't provided the larger context here but, in general, it is a bad idea to try to put commands in variables. See "I'm trying to put a command in a variable, but the complex cases always fail!".
Separately, regarding the variable COMMAND
, it is better practice to use lower or mixed case for your shell variables. The system uses upper case for its variables and you don't want to accidentally overwrite one of them.
Note: this answer is for the first version of the question.
First, let's define i
with the tab:
$ i=$'ls -ltcd ~'
Now, let's try your commands without and then with double-quotes:
$ echo $i | cut -f2
ls -l cd ~
$ echo "$i" | cut -f2
cd ~
If you want cut
to work as expected, you need to put $i
in double-quotes. Without the double-quotes, the shell performs, among other things, word splitting which results in the tab being replaced by a blank. This prevents the cut
command from working as you expect.
Doing the assignment to Command does not change this:
$ Command=$(echo $i | cut -f2); declare -p Command
declare -- Command="ls -l cd ~"
$ Command=$(echo "$i" | cut -f2); declare -p Command
declare -- Command="cd ~"
General comments
You haven't provided the larger context here but, in general, it is a bad idea to try to put commands in variables. See "I'm trying to put a command in a variable, but the complex cases always fail!".
Separately, regarding the variable COMMAND
, it is better practice to use lower or mixed case for your shell variables. The system uses upper case for its variables and you don't want to accidentally overwrite one of them.
edited Apr 10 at 22:19
answered Apr 10 at 22:14
John1024John1024
48.7k5114129
48.7k5114129
1
Thank you for your help and comments! It works now.
– Alex
Apr 10 at 22:24
add a comment |
1
Thank you for your help and comments! It works now.
– Alex
Apr 10 at 22:24
1
1
Thank you for your help and comments! It works now.
– Alex
Apr 10 at 22:24
Thank you for your help and comments! It works now.
– Alex
Apr 10 at 22:24
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%2f511772%2fhow-to-prevent-a-command-from-ticks-from-being-executed-in-linux-bash-scripting%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
1
I don't think your characterisation of what's happening is accurate. Could you edit in a transcript of your experiment and the result you're seeing?
– Michael Homer
Apr 10 at 22:15