Add prefix and suffix to an input and send it as a command

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











up vote
0
down vote

favorite












I am adding some rules to an application. I want to make a bash script which would take my input, for example: 'abc', add a prefix 'pqr' and a suffix 'xyz' to the input and send it as a command.



In this case the command to be sent would be pqrabcxyz without any spaces as I didn't add them.



The script I am using is



#!/bin/bash
read -p "ID to be banned: " cmd
"iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"






share|improve this question






















  • Sample of real input (is it form a file? How are you getting this input?) and expect result would help the most. Any code you have tried will also let us know what your skill level is really like too.
    – Tigger
    Dec 6 '17 at 6:00















up vote
0
down vote

favorite












I am adding some rules to an application. I want to make a bash script which would take my input, for example: 'abc', add a prefix 'pqr' and a suffix 'xyz' to the input and send it as a command.



In this case the command to be sent would be pqrabcxyz without any spaces as I didn't add them.



The script I am using is



#!/bin/bash
read -p "ID to be banned: " cmd
"iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"






share|improve this question






















  • Sample of real input (is it form a file? How are you getting this input?) and expect result would help the most. Any code you have tried will also let us know what your skill level is really like too.
    – Tigger
    Dec 6 '17 at 6:00













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am adding some rules to an application. I want to make a bash script which would take my input, for example: 'abc', add a prefix 'pqr' and a suffix 'xyz' to the input and send it as a command.



In this case the command to be sent would be pqrabcxyz without any spaces as I didn't add them.



The script I am using is



#!/bin/bash
read -p "ID to be banned: " cmd
"iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"






share|improve this question














I am adding some rules to an application. I want to make a bash script which would take my input, for example: 'abc', add a prefix 'pqr' and a suffix 'xyz' to the input and send it as a command.



In this case the command to be sent would be pqrabcxyz without any spaces as I didn't add them.



The script I am using is



#!/bin/bash
read -p "ID to be banned: " cmd
"iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"








share|improve this question













share|improve this question




share|improve this question








edited Jan 6 at 14:58









grg

1857




1857










asked Dec 6 '17 at 5:43









Ayush Mishra

84




84











  • Sample of real input (is it form a file? How are you getting this input?) and expect result would help the most. Any code you have tried will also let us know what your skill level is really like too.
    – Tigger
    Dec 6 '17 at 6:00

















  • Sample of real input (is it form a file? How are you getting this input?) and expect result would help the most. Any code you have tried will also let us know what your skill level is really like too.
    – Tigger
    Dec 6 '17 at 6:00
















Sample of real input (is it form a file? How are you getting this input?) and expect result would help the most. Any code you have tried will also let us know what your skill level is really like too.
– Tigger
Dec 6 '17 at 6:00





Sample of real input (is it form a file? How are you getting this input?) and expect result would help the most. Any code you have tried will also let us know what your skill level is really like too.
– Tigger
Dec 6 '17 at 6:00











2 Answers
2






active

oldest

votes

















up vote
1
down vote













#!/bin/bash
read -p "Please type in your command" cmd
pqr"$cmd"xyz


Based on the limited information in the question, this should be enough. I hope that @ayush-mishra can be more specific.



Answer edited thanks to reminder by @grgarside






share|improve this answer






















  • The Script I am Using is: #!/bin/bash read -p "ID to be banned: " cmd "iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"
    – Ayush Mishra
    Dec 6 '17 at 7:10










  • But It is Not working. It Shows no command found
    – Ayush Mishra
    Dec 6 '17 at 7:10










  • You have to be root to run iptables. Switch to root first with su or use sudo in a proper way so that iptables is invoked as root. You may also need to change iptables to /sbin/iptables
    – Weijun Zhou
    Dec 6 '17 at 7:55










  • Its not working
    – Ayush Mishra
    Dec 6 '17 at 8:54










  • @Ayush Don't use "…" around the iptables command.
    – grg
    Jan 6 at 14:14

















up vote
0
down vote













You can try with below command



Method1



echo "abc" | sed "s/^/pqr/g" | sed "s/$/xyz/g"



Method2




#!/bin/bash
j="pqr"
z="xyz"
echo "abc" | sed "s/^/"$j"/g" | sed "s/$/"$z"/g"







share|improve this answer




















    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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f409104%2fadd-prefix-and-suffix-to-an-input-and-send-it-as-a-command%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    #!/bin/bash
    read -p "Please type in your command" cmd
    pqr"$cmd"xyz


    Based on the limited information in the question, this should be enough. I hope that @ayush-mishra can be more specific.



    Answer edited thanks to reminder by @grgarside






    share|improve this answer






















    • The Script I am Using is: #!/bin/bash read -p "ID to be banned: " cmd "iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • But It is Not working. It Shows no command found
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • You have to be root to run iptables. Switch to root first with su or use sudo in a proper way so that iptables is invoked as root. You may also need to change iptables to /sbin/iptables
      – Weijun Zhou
      Dec 6 '17 at 7:55










    • Its not working
      – Ayush Mishra
      Dec 6 '17 at 8:54










    • @Ayush Don't use "…" around the iptables command.
      – grg
      Jan 6 at 14:14














    up vote
    1
    down vote













    #!/bin/bash
    read -p "Please type in your command" cmd
    pqr"$cmd"xyz


    Based on the limited information in the question, this should be enough. I hope that @ayush-mishra can be more specific.



    Answer edited thanks to reminder by @grgarside






    share|improve this answer






















    • The Script I am Using is: #!/bin/bash read -p "ID to be banned: " cmd "iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • But It is Not working. It Shows no command found
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • You have to be root to run iptables. Switch to root first with su or use sudo in a proper way so that iptables is invoked as root. You may also need to change iptables to /sbin/iptables
      – Weijun Zhou
      Dec 6 '17 at 7:55










    • Its not working
      – Ayush Mishra
      Dec 6 '17 at 8:54










    • @Ayush Don't use "…" around the iptables command.
      – grg
      Jan 6 at 14:14












    up vote
    1
    down vote










    up vote
    1
    down vote









    #!/bin/bash
    read -p "Please type in your command" cmd
    pqr"$cmd"xyz


    Based on the limited information in the question, this should be enough. I hope that @ayush-mishra can be more specific.



    Answer edited thanks to reminder by @grgarside






    share|improve this answer














    #!/bin/bash
    read -p "Please type in your command" cmd
    pqr"$cmd"xyz


    Based on the limited information in the question, this should be enough. I hope that @ayush-mishra can be more specific.



    Answer edited thanks to reminder by @grgarside







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 6 at 14:55

























    answered Dec 6 '17 at 6:11









    Weijun Zhou

    1,434119




    1,434119











    • The Script I am Using is: #!/bin/bash read -p "ID to be banned: " cmd "iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • But It is Not working. It Shows no command found
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • You have to be root to run iptables. Switch to root first with su or use sudo in a proper way so that iptables is invoked as root. You may also need to change iptables to /sbin/iptables
      – Weijun Zhou
      Dec 6 '17 at 7:55










    • Its not working
      – Ayush Mishra
      Dec 6 '17 at 8:54










    • @Ayush Don't use "…" around the iptables command.
      – grg
      Jan 6 at 14:14
















    • The Script I am Using is: #!/bin/bash read -p "ID to be banned: " cmd "iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • But It is Not working. It Shows no command found
      – Ayush Mishra
      Dec 6 '17 at 7:10










    • You have to be root to run iptables. Switch to root first with su or use sudo in a proper way so that iptables is invoked as root. You may also need to change iptables to /sbin/iptables
      – Weijun Zhou
      Dec 6 '17 at 7:55










    • Its not working
      – Ayush Mishra
      Dec 6 '17 at 8:54










    • @Ayush Don't use "…" around the iptables command.
      – grg
      Jan 6 at 14:14















    The Script I am Using is: #!/bin/bash read -p "ID to be banned: " cmd "iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"
    – Ayush Mishra
    Dec 6 '17 at 7:10




    The Script I am Using is: #!/bin/bash read -p "ID to be banned: " cmd "iptables --append INPUT --match string --algo kmp --string '$cmd' --jump DROP -p udp"
    – Ayush Mishra
    Dec 6 '17 at 7:10












    But It is Not working. It Shows no command found
    – Ayush Mishra
    Dec 6 '17 at 7:10




    But It is Not working. It Shows no command found
    – Ayush Mishra
    Dec 6 '17 at 7:10












    You have to be root to run iptables. Switch to root first with su or use sudo in a proper way so that iptables is invoked as root. You may also need to change iptables to /sbin/iptables
    – Weijun Zhou
    Dec 6 '17 at 7:55




    You have to be root to run iptables. Switch to root first with su or use sudo in a proper way so that iptables is invoked as root. You may also need to change iptables to /sbin/iptables
    – Weijun Zhou
    Dec 6 '17 at 7:55












    Its not working
    – Ayush Mishra
    Dec 6 '17 at 8:54




    Its not working
    – Ayush Mishra
    Dec 6 '17 at 8:54












    @Ayush Don't use "…" around the iptables command.
    – grg
    Jan 6 at 14:14




    @Ayush Don't use "…" around the iptables command.
    – grg
    Jan 6 at 14:14












    up vote
    0
    down vote













    You can try with below command



    Method1



    echo "abc" | sed "s/^/pqr/g" | sed "s/$/xyz/g"



    Method2




    #!/bin/bash
    j="pqr"
    z="xyz"
    echo "abc" | sed "s/^/"$j"/g" | sed "s/$/"$z"/g"







    share|improve this answer
























      up vote
      0
      down vote













      You can try with below command



      Method1



      echo "abc" | sed "s/^/pqr/g" | sed "s/$/xyz/g"



      Method2




      #!/bin/bash
      j="pqr"
      z="xyz"
      echo "abc" | sed "s/^/"$j"/g" | sed "s/$/"$z"/g"







      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        You can try with below command



        Method1



        echo "abc" | sed "s/^/pqr/g" | sed "s/$/xyz/g"



        Method2




        #!/bin/bash
        j="pqr"
        z="xyz"
        echo "abc" | sed "s/^/"$j"/g" | sed "s/$/"$z"/g"







        share|improve this answer












        You can try with below command



        Method1



        echo "abc" | sed "s/^/pqr/g" | sed "s/$/xyz/g"



        Method2




        #!/bin/bash
        j="pqr"
        z="xyz"
        echo "abc" | sed "s/^/"$j"/g" | sed "s/$/"$z"/g"








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 '17 at 6:01









        Praveen Kumar BS

        1,010128




        1,010128



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409104%2fadd-prefix-and-suffix-to-an-input-and-send-it-as-a-command%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

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

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay