Concatenate and pass as parameter, bash

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












Need to remove default gateway. For example, there is an IP 192.168.4.15 with default gateway 192.168.4.14. I connect to WLAN with gw 10.0.0.1 and after that I would like do remove previous gw.



 IFS='.' read -ra IPARR <<< "$IP"
Gateway="$IPARR[0].$IPARR[1].$IPARR[2].14"
ssh blah@$IP '/sbin/route -v del default gw $Gateway;'
#ssh blah@$IP '/sbin/ip route delete $Gateway dev rndis0;'
#ssh blah@$IP '/sbin/route -n'


Both ways don't work. However, it is possible to remove it if I ssh into machine. My guess is that something wrong with passing $Gateway variable. Any suggestions?










share|improve this question























  • You're using the wrong quotes. '' prevent variable expansion.
    – muru
    Dec 30 '14 at 10:52







  • 1




    @muru, or with ssh it will mean that the variable will get expanded on the remote host rather than locally where the Gateway variable has been set.
    – Graeme
    Dec 30 '14 at 11:10










  • @Graeme Indeed.
    – muru
    Dec 30 '14 at 11:12










  • Thanks guys, I have been trying to figure out what is wrong for a few hours already.
    – mikedanylov
    Dec 30 '14 at 11:17










  • duplicate: stackoverflow.com/q/27703579/7552
    – glenn jackman
    Dec 30 '14 at 13:54














up vote
2
down vote

favorite
1












Need to remove default gateway. For example, there is an IP 192.168.4.15 with default gateway 192.168.4.14. I connect to WLAN with gw 10.0.0.1 and after that I would like do remove previous gw.



 IFS='.' read -ra IPARR <<< "$IP"
Gateway="$IPARR[0].$IPARR[1].$IPARR[2].14"
ssh blah@$IP '/sbin/route -v del default gw $Gateway;'
#ssh blah@$IP '/sbin/ip route delete $Gateway dev rndis0;'
#ssh blah@$IP '/sbin/route -n'


Both ways don't work. However, it is possible to remove it if I ssh into machine. My guess is that something wrong with passing $Gateway variable. Any suggestions?










share|improve this question























  • You're using the wrong quotes. '' prevent variable expansion.
    – muru
    Dec 30 '14 at 10:52







  • 1




    @muru, or with ssh it will mean that the variable will get expanded on the remote host rather than locally where the Gateway variable has been set.
    – Graeme
    Dec 30 '14 at 11:10










  • @Graeme Indeed.
    – muru
    Dec 30 '14 at 11:12










  • Thanks guys, I have been trying to figure out what is wrong for a few hours already.
    – mikedanylov
    Dec 30 '14 at 11:17










  • duplicate: stackoverflow.com/q/27703579/7552
    – glenn jackman
    Dec 30 '14 at 13:54












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





Need to remove default gateway. For example, there is an IP 192.168.4.15 with default gateway 192.168.4.14. I connect to WLAN with gw 10.0.0.1 and after that I would like do remove previous gw.



 IFS='.' read -ra IPARR <<< "$IP"
Gateway="$IPARR[0].$IPARR[1].$IPARR[2].14"
ssh blah@$IP '/sbin/route -v del default gw $Gateway;'
#ssh blah@$IP '/sbin/ip route delete $Gateway dev rndis0;'
#ssh blah@$IP '/sbin/route -n'


Both ways don't work. However, it is possible to remove it if I ssh into machine. My guess is that something wrong with passing $Gateway variable. Any suggestions?










share|improve this question















Need to remove default gateway. For example, there is an IP 192.168.4.15 with default gateway 192.168.4.14. I connect to WLAN with gw 10.0.0.1 and after that I would like do remove previous gw.



 IFS='.' read -ra IPARR <<< "$IP"
Gateway="$IPARR[0].$IPARR[1].$IPARR[2].14"
ssh blah@$IP '/sbin/route -v del default gw $Gateway;'
#ssh blah@$IP '/sbin/ip route delete $Gateway dev rndis0;'
#ssh blah@$IP '/sbin/route -n'


Both ways don't work. However, it is possible to remove it if I ssh into machine. My guess is that something wrong with passing $Gateway variable. Any suggestions?







bash ssh command-line






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 22:27









Rui F Ribeiro

38.2k1475125




38.2k1475125










asked Dec 30 '14 at 10:48









mikedanylov

1314




1314











  • You're using the wrong quotes. '' prevent variable expansion.
    – muru
    Dec 30 '14 at 10:52







  • 1




    @muru, or with ssh it will mean that the variable will get expanded on the remote host rather than locally where the Gateway variable has been set.
    – Graeme
    Dec 30 '14 at 11:10










  • @Graeme Indeed.
    – muru
    Dec 30 '14 at 11:12










  • Thanks guys, I have been trying to figure out what is wrong for a few hours already.
    – mikedanylov
    Dec 30 '14 at 11:17










  • duplicate: stackoverflow.com/q/27703579/7552
    – glenn jackman
    Dec 30 '14 at 13:54
















  • You're using the wrong quotes. '' prevent variable expansion.
    – muru
    Dec 30 '14 at 10:52







  • 1




    @muru, or with ssh it will mean that the variable will get expanded on the remote host rather than locally where the Gateway variable has been set.
    – Graeme
    Dec 30 '14 at 11:10










  • @Graeme Indeed.
    – muru
    Dec 30 '14 at 11:12










  • Thanks guys, I have been trying to figure out what is wrong for a few hours already.
    – mikedanylov
    Dec 30 '14 at 11:17










  • duplicate: stackoverflow.com/q/27703579/7552
    – glenn jackman
    Dec 30 '14 at 13:54















You're using the wrong quotes. '' prevent variable expansion.
– muru
Dec 30 '14 at 10:52





You're using the wrong quotes. '' prevent variable expansion.
– muru
Dec 30 '14 at 10:52





1




1




@muru, or with ssh it will mean that the variable will get expanded on the remote host rather than locally where the Gateway variable has been set.
– Graeme
Dec 30 '14 at 11:10




@muru, or with ssh it will mean that the variable will get expanded on the remote host rather than locally where the Gateway variable has been set.
– Graeme
Dec 30 '14 at 11:10












@Graeme Indeed.
– muru
Dec 30 '14 at 11:12




@Graeme Indeed.
– muru
Dec 30 '14 at 11:12












Thanks guys, I have been trying to figure out what is wrong for a few hours already.
– mikedanylov
Dec 30 '14 at 11:17




Thanks guys, I have been trying to figure out what is wrong for a few hours already.
– mikedanylov
Dec 30 '14 at 11:17












duplicate: stackoverflow.com/q/27703579/7552
– glenn jackman
Dec 30 '14 at 13:54




duplicate: stackoverflow.com/q/27703579/7552
– glenn jackman
Dec 30 '14 at 13:54










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










So, the answer is to use double quotes when ssh'ing into machine:



ssh blah@$IP "/sbin/route -v del default gw $Gateway;"





share|improve this answer




















  • You should stop using obsolete commands, and start using ip instead: ssh blah@IP "/sbin/ip route del default via $Gateway"
    – MariusMatutiae
    Dec 30 '14 at 14:29










  • @MariusMatutiae, could you explain more what is the difference between route and ip route?
    – mikedanylov
    Dec 31 '14 at 8:42










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',
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%2f176573%2fconcatenate-and-pass-as-parameter-bash%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








up vote
2
down vote



accepted










So, the answer is to use double quotes when ssh'ing into machine:



ssh blah@$IP "/sbin/route -v del default gw $Gateway;"





share|improve this answer




















  • You should stop using obsolete commands, and start using ip instead: ssh blah@IP "/sbin/ip route del default via $Gateway"
    – MariusMatutiae
    Dec 30 '14 at 14:29










  • @MariusMatutiae, could you explain more what is the difference between route and ip route?
    – mikedanylov
    Dec 31 '14 at 8:42














up vote
2
down vote



accepted










So, the answer is to use double quotes when ssh'ing into machine:



ssh blah@$IP "/sbin/route -v del default gw $Gateway;"





share|improve this answer




















  • You should stop using obsolete commands, and start using ip instead: ssh blah@IP "/sbin/ip route del default via $Gateway"
    – MariusMatutiae
    Dec 30 '14 at 14:29










  • @MariusMatutiae, could you explain more what is the difference between route and ip route?
    – mikedanylov
    Dec 31 '14 at 8:42












up vote
2
down vote



accepted







up vote
2
down vote



accepted






So, the answer is to use double quotes when ssh'ing into machine:



ssh blah@$IP "/sbin/route -v del default gw $Gateway;"





share|improve this answer












So, the answer is to use double quotes when ssh'ing into machine:



ssh blah@$IP "/sbin/route -v del default gw $Gateway;"






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 30 '14 at 11:27









mikedanylov

1314




1314











  • You should stop using obsolete commands, and start using ip instead: ssh blah@IP "/sbin/ip route del default via $Gateway"
    – MariusMatutiae
    Dec 30 '14 at 14:29










  • @MariusMatutiae, could you explain more what is the difference between route and ip route?
    – mikedanylov
    Dec 31 '14 at 8:42
















  • You should stop using obsolete commands, and start using ip instead: ssh blah@IP "/sbin/ip route del default via $Gateway"
    – MariusMatutiae
    Dec 30 '14 at 14:29










  • @MariusMatutiae, could you explain more what is the difference between route and ip route?
    – mikedanylov
    Dec 31 '14 at 8:42















You should stop using obsolete commands, and start using ip instead: ssh blah@IP "/sbin/ip route del default via $Gateway"
– MariusMatutiae
Dec 30 '14 at 14:29




You should stop using obsolete commands, and start using ip instead: ssh blah@IP "/sbin/ip route del default via $Gateway"
– MariusMatutiae
Dec 30 '14 at 14:29












@MariusMatutiae, could you explain more what is the difference between route and ip route?
– mikedanylov
Dec 31 '14 at 8:42




@MariusMatutiae, could you explain more what is the difference between route and ip route?
– mikedanylov
Dec 31 '14 at 8:42

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f176573%2fconcatenate-and-pass-as-parameter-bash%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

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?