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;








1















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?










share|improve this question



















  • 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















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?










share|improve this question



















  • 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








1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer




















  • 1





    Thank you for your help and comments! It works now.

    – Alex
    Apr 10 at 22:24











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
);



);













draft saved

draft discarded


















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









2














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.






share|improve this answer




















  • 1





    Thank you for your help and comments! It works now.

    – Alex
    Apr 10 at 22:24















2














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.






share|improve this answer




















  • 1





    Thank you for your help and comments! It works now.

    – Alex
    Apr 10 at 22:24













2












2








2







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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












  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In 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 ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.