Add prefix and suffix to an input and send it as a command
Clash 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"
linux bash ubuntu
add a comment |Â
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"
linux bash ubuntu
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
add a comment |Â
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"
linux bash ubuntu
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"
linux bash ubuntu
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
add a comment |Â
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
add a comment |Â
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
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 runiptables
. Switch to root first withsu
or usesudo
in a proper way so thatiptables
is invoked as root. You may also need to changeiptables
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
 |Â
show 1 more comment
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"
add a comment |Â
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
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 runiptables
. Switch to root first withsu
or usesudo
in a proper way so thatiptables
is invoked as root. You may also need to changeiptables
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
 |Â
show 1 more comment
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
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 runiptables
. Switch to root first withsu
or usesudo
in a proper way so thatiptables
is invoked as root. You may also need to changeiptables
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
 |Â
show 1 more comment
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
#!/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
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 runiptables
. Switch to root first withsu
or usesudo
in a proper way so thatiptables
is invoked as root. You may also need to changeiptables
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
 |Â
show 1 more comment
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 runiptables
. Switch to root first withsu
or usesudo
in a proper way so thatiptables
is invoked as root. You may also need to changeiptables
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
 |Â
show 1 more comment
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"
add a comment |Â
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"
add a comment |Â
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"
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"
answered Dec 6 '17 at 6:01
Praveen Kumar BS
1,010128
1,010128
add a comment |Â
add a comment |Â
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
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
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
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
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
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