bash scripts escape char problems


Results 1 to 13 of 13

Thread: bash scripts escape char problems

  1. #1
    Join Date
    Sep 2005
    Posts
    681

    bash scripts escape char problems

    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.

  2. #2
    Join Date
    Sep 2005
    Posts
    681
    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

  3. #3
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    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.

  4. #4
    Join Date
    Sep 2005
    Posts
    681
    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.

  5. #5
    Join Date
    Sep 2005
    Posts
    681
    and oh yearh i meant to cap the LOG -m limit --limit 1/second -j LOG

    just a type o sorry about that

  6. #6
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    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)

  7. #7
    Join Date
    Sep 2005
    Posts
    681
    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.......

  8. #8
    Join Date
    Sep 2005
    Posts
    681
    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 .

  9. #9
    Join Date
    Sep 2002
    Location
    Valencia, California
    Posts
    436
    Quote Originally Posted by crow2icedearth
    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:
    Code:
    cat > test.sh
    and then paste in your script, or something simple like:
    Code:
    sudo \
    whoami
    echo this is\
        totally working.
    Hit ctrl-d when you're done pasting.

  10. #10
    Join Date
    Sep 2005
    Posts
    681
    no but the iptables relies on the kernel to have it netfilters ......

  11. #11
    Join Date
    Sep 2005
    Posts
    681
    well that seemed to work...... so is the problem vim not keymapping correctly ?

  12. #12
    Join Date
    Sep 2005
    Posts
    681
    now it seems to work in vim. thts a very strang problem...... rebooted the machine and it all works fine

  13. #13
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •