bash script help: escaping the '*'


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script help: escaping the '*'
# 1  
Old 10-07-2005
bash script help: escaping the '*'

hi there. i have a simple bash script that reads a word from a text file
one at a time, and if a '*' character is encountered, it prints a message.
however it doesn't work as i expected. Smilie what am i doing wrong here?
thanks very much for the help Smilie

Code:
for word in `cat $DOC`
do
        if [ "$word" = "\*" ]; then
                echo -e "\n\nASTERISK\n\n"
        fi
done

# 2  
Old 10-07-2005
Read man bash for [[ expression ]]

Code:
for word in `cat $DOC`
do
        if [[ "$word" = *"*"* ]] ; then
                echo -e "\n\nASTERISK\n\n"
        fi
done

vino
# 3  
Old 10-07-2005
still doesn't work.... Smilie
# 4  
Old 10-07-2005
What error does it give ? And what shell are you running ?

Last edited by vino; 10-07-2005 at 05:08 AM..
# 5  
Old 10-07-2005
im using #!/bin/bash at it doesnt give any errors and doesnt write anything to stdout.

here's a sample of the text file im reading.. the problem arises from that single
'*' character just above Links.

Code:
<DOC>
<DOCNO>EUK-003-373651945</DOCNO>
<DOCID>EUK-003-373651945</DOCID>
<TEXT>
   [1]Back to Full Graphics
     _________________________________________________________________

   *
   Links

   The Foreign Office works with a variety of different organisations and
   government bodies to achieve its human rights objectives. Click on the
   links on the right for a list of relevant websites in each sector.
   The Foreign and Commonwealth Office London is not responsible for the
   contents or reliability of the linked websites and does not
   necessarily endorse the views expressed within them. We cannot
   guarantee that these links will work all of the time and we have no
   control over availability of the linked pages.

References

   1. http://www.fco.gov.uk/servlet/Front?pagename=OpenMarket/Xcelerate/ShowPage
&c=Page&cid=1028302592178
</TEXT>

# 6  
Old 10-07-2005
Do you just want to detect *'s ? Or get rid of it ? What is it that you want ?

This sed command will output the file sans the *'s

Code:
sed -e 's#*##g' $DOC

# 7  
Old 10-07-2005
sorry i did not make myself clear..

i wanted to read each word from the file,
if its a '*', echo "\\*" >> $output-file (escape the '*')
else, echo "$word" >> $output-file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. UNIX for Beginners Questions & Answers

Help with bash escaping while using screen command

Hello, everyone. I'm currently trying to write a command system for a Minecraft server using screen. Here are the scripts I'm currently using. 0.sh #!/bin/bash screen -S Test114 -dm java -Xmx4G -jar server.jar nogui 1.sh #!/bin/bash args="$@" args2="${args@Q}" #args3=`printf '%q\n'... (2 Replies)
Discussion started by: Develon
2 Replies

3. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

4. Shell Programming and Scripting

Bash Vs. Bourne REGEX: metacharacters escaping

I am currently reading a very old reference from O'Reilly: Sed and Awk 2nd Edition reprinted in 2000. So far, it's a solid read and still very relevant. I'd highly recommend this to anyone. The only problem I have with this book is that I had to resort to bourne shell to get my examples to work... (3 Replies)
Discussion started by: ConcealedKnight
3 Replies

5. Shell Programming and Scripting

Wanted: Help with escaping bash command line arguments

Please forgive me if this is the wrong forum. I want to execute some one liners with the groovy programming language and I'm having trouble escaping the special characters to accommodate bash. Here is one of the lines that is giving me trouble: groovy -e "(new... (1 Reply)
Discussion started by: siegfried
1 Replies

6. Shell Programming and Scripting

Escaping problem in a shell script

Hi, i made a gnuplot script which accepts a filename as parameter (using gnuplot -e) now i want to run this script from a shell script, the correct command (with a concrete parameter) looks like this: gnuplot -e 'name="filename.dat;col=2"' gplscript.gpl my shell script looks like this: ... (4 Replies)
Discussion started by: franko007
4 Replies

7. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

8. Shell Programming and Scripting

escaping double-quotes inside the script?

I'm having a strange problem with escaping double-quotes. I have a script that looks like this: #!/bin/bash for HOST in `cat $INFILE | grep -v ^#` do for VFILER in `some_command` do echo " " echo -e '\E The problem with ssh command... (3 Replies)
Discussion started by: GKnight
3 Replies

9. Shell Programming and Scripting

Escaping '*' in Bash

I have the following situation ============ export DirectoryName=/tmp/xyz if ; then some_new_env=$DirectoryName"/*" ======================= I tried all the ways of escaping the '*', but still the shell seems to expand the '*' character. I want some_new_env to contain "/tmp/xyz/*" ... (7 Replies)
Discussion started by: rkshukla14
7 Replies

10. Shell Programming and Scripting

Escaping apostrophe using shell script

Hi, I am using the KSH shell. I am facing a problem of escaping apostrophe('), that is occuring in a variable. I used the following command, but in vain item=`echo $item|sed 's/&apos;/\'/g'` this code replaces the occurance of &apos; in an xml file to apostrophe(') symbol. The output of... (2 Replies)
Discussion started by: mradul_kaushik
2 Replies
Login or Register to Ask a Question