Escaping '*' in Bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Escaping '*' in Bash
# 1  
Old 04-04-2007
Escaping '*' in Bash

I have the following situation

============
export DirectoryName=/tmp/xyz

if [ -d $DirectoryName ] ; 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/*"

Any ideas?
# 2  
Old 04-04-2007
try:
set -f

before using the * or use single quotes when defining it and double quotes around the full expression later.

Code:
$ echo *
test1 test2 test3
$ set -f
$ echo *
*
$ set +f
$ a='*'
$ echo "$a"
*

# 3  
Old 04-04-2007
set −f command disables globbing
# 4  
Old 04-04-2007
how do I re-enable it after I am done with 'set -f'?
# 5  
Old 04-04-2007
use
Code:
set +f

# 6  
Old 04-04-2007
Got it ' set +f *'!!


Thanks very much to both you for your prompt help!

cheers
# 7  
Old 04-04-2007
Use either an single quote '
or
Use backslash to escape the special characters
or
Turn of globbing by using "set -f " in the above script

Check this for more : http://www.grymoire.com/Unix/Quote.html

Thanks,
Nagarajan Ganesan.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Escaping the \

So I understand that I should be able to ouput a literal \ by escaping it with a preceding \. My problem is that I am trying to ouput a script that will subsequently be run on a different system with UNC pathing, so I want to ouput two \\ in a row, but escaping them both in sequential order is not... (4 Replies)
Discussion started by: JourneyRider
4 Replies

3. 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

4. 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

5. Shell Programming and Scripting

escaping path

Hi I use : path=/var/www/admin echo "$path" | sed -e 's/\//\\\//g' this return \/var\/www\/admin and is ok. but path2=`echo "$path" | sed -e 's/\//\\\//g'` echo $path2 return an error: sed: -e expression #1, char 9: unknown option to `s' Can anyone help me? Thanks (3 Replies)
Discussion started by: georgian
3 Replies

6. Shell Programming and Scripting

escaping '

I'm cleaning this from some html files style='' but when I try 's/style=\'\''//' I get an unmatched ' error (4 Replies)
Discussion started by: dba_frog
4 Replies

7. Shell Programming and Scripting

Escaping ** correctly

Hello This should be easy, but bash is giving me headaches. At the command line the following command works: duplicity --include /home --exclude '**' / file:///foo Doing that from a script is not straightforward. Note that it is basically a requirement that I place the... (3 Replies)
Discussion started by: brsett
3 Replies

8. UNIX for Dummies Questions & Answers

Escaping backslash

I have a variable containt something like this, c:\mask\mask. How can I escape "\" in the values? I want the value as it it. (9 Replies)
Discussion started by: swmk
9 Replies

9. Shell Programming and Scripting

incorrect quotes/escaping?

Hi all, i have a perl script. from within the perl script, i am calling a system command which i need to pass in a perl variable. but the variable substitution does not seems to happen. would like to find out where is the missing escape character or extra quotes;or what is my mistake. ... (2 Replies)
Discussion started by: new2ss
2 Replies

10. Shell Programming and Scripting

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. :o what am i doing wrong here? thanks very much for the help :) for word in `cat $DOC` do if... (18 Replies)
Discussion started by: mark_nsx
18 Replies
Login or Register to Ask a Question