Jump to content

shell - escaping special characters in scripts?


Recommended Posts

when running scripts i know that if there is a space in a file you escape it with a \

so "blah blah" becomes "blah\ blah".

How do you escape characters like &, (, and )?

Edited by johnnyv
Link to comment
Share on other sites

also you can scape such characters by quoting them:

  • with double quotes you scape everything except $ and \ if it's followed by $
  • and with sigle quotes you scape all

for example:

~$ echo this is my path: $PATH; OK?
this is my path: /bin:/home/aru/bin:/usr/bin:/usr/games:/usr/local/bin:/usr/X11R6/bin
bash: OK?: command not found
~$ echo "this is my path: $PATH; OK?"
this is my path: /bin:/home/aru/bin:/usr/bin:/usr/games:/usr/local/bin:/usr/X11R6/bin; OK?
~$ echo "this is my path: \$PATH; OK?"
this is my path: $PATH; OK?
~$ echo 'this is my path: $PATH; OK?'
this is my path: $PATH; OK?
~$

Edited by aru
Link to comment
Share on other sites

Thanks for the tips aru!

I am calling the shell commands via php's system_exec() function.

 

Mainly "antiword -t $filepath", "pdftotext $filepath -", and "cat $filepath"

It's for a search engine spider i have hacked together, and lucky for me thats all the non php stuff i have to deal with ;)

Edited by johnnyv
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...