Click to See Complete Forum and Search --> : bash scripts escape char problems


crow2icedearth
11-08-2005, 10:35 AM
hi everyone i am trying to use the backslash escape char when writting an iptables script the problem im having its it doesnt work.

if i type the iptables command into the shell it works fine with backslash spaces. what do i need to do to get the script to work with \ char ? i find it strange that it works on the command line fine but when its in a script file it doesnt.

crow2icedearth
11-08-2005, 01:56 PM
my iptable script test works fine i tried it on my other linux box and it worked the escap char work perfect. i still cant figure out why it wont on my slackware box thou ...... its using bash 3.x.x i think

Sepero
11-08-2005, 04:23 PM
Perhaps you aren't using a bash shell. To be sure, you should start the file with:
#!/bin/bash

If that doesn't work, we're going to need an example of what you're talking about.

crow2icedearth
11-09-2005, 07:11 AM
im using bash . and i have #!/bin/bash in my script thats given. the \ at end of line doesnt work .

example would be

iptables -F
iptables -A INPUT -i eth0 \
-p icmp --icmp-type echo-request \
-m limit --limit 1/second -j log

the script whould give me an error telling me the -p isnt a command which is given. and in otherwords the \ right after eth0 isnt working. if i type that command in the command line prompt it works perfect with no error . im currently learning iptables.

crow2icedearth
11-09-2005, 07:13 AM
and oh yearh i meant to cap the LOG -m limit --limit 1/second -j LOG

just a type o sorry about that

Sepero
11-09-2005, 08:29 AM
Did you originally create this file on a Microsoft or Apple OS? If so, Linux may be seeing garbage at the end of each line. (\n\r\c)
Can you post the file so that we can inspect it ourselves? (zip it first)

crow2icedearth
11-09-2005, 12:23 PM
NO i dont use windows........i use vi to create it what im use to use its not the file
its in text...... its a problem with bash and iptables ..... not the text file which is created with vi.......

crow2icedearth
11-09-2005, 12:25 PM
the only thing i can think of is the kernel is missing options to not let lptables use blackslash. because it works on the box i compiled fine but doesnt on the test 2.6.13 slackware kernel .

JThundley
11-09-2005, 01:52 PM
the only thing i can think of is the kernel is missing options to not let lptables use blackslash. because it works on the box i compiled fine but doesnt on the test 2.6.13 slackware kernel .

That's ridiculous, there are no kernel options that have to do with how you type stuff in in bash.

What's the output of 'file yourscript.sh' ? backslash escaping newlines works fine for me the way you're doing it. Try catting the text in instead of using an editor:
cat > test.sh and then paste in your script, or something simple like:
sudo \
whoami
echo this is\
totally working.

Hit ctrl-d when you're done pasting.

crow2icedearth
11-09-2005, 01:58 PM
no but the iptables relies on the kernel to have it netfilters ......

crow2icedearth
11-09-2005, 02:01 PM
well that seemed to work...... so is the problem vim not keymapping correctly ?

crow2icedearth
11-09-2005, 02:04 PM
now it seems to work in vim. thts a very strang problem...... rebooted the machine and it all works fine

Sepero
11-09-2005, 03:04 PM
Solved?
:)