Sponsored Content
Top Forums Shell Programming and Scripting Need to use asterisk in variable Post 302914630 by Scrutinizer on Wednesday 27th of August 2014 03:40:11 AM
Old 08-27-2014
Indeed the use of double quotes around "$FLAG" prevents the expansion of the wildcard. They can be left out, but then the test will fail if there are more files present with this pattern. To test for the presence of one of more files you could try:

Code:
FLAG=/test/Marker_*.tmp

file_exists() {
  for _i do
    [ -f "$_i" ] && break
  done
}

if file_exists $FLAG
then
  echo "One or more marker files exist"
else
  echo "No marker files have arrived yet"
fi



---
Quote:
Originally Posted by Don Cragun
Try any one of:
Code:
FLAG="/test/Marker_*.tmp"
FLAG='/test/Marker_*.tmp'
FLAG=/test/Marker_\*.tmp
FLAG=/test/Marker_"*".tmp
FLAG=/test/Marker_'*'.tmp

That should not be necessary, since wildcards are not expanded in variable assignments...

Last edited by Scrutinizer; 08-27-2014 at 04:54 AM..
 

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing asterisk to a script as variable

I'm writing a script that will ssh to a number of hosts and run commands. I'm a bit stumped at the moment as some of the commands that I need to run contain wildcards (i.e. *), and so far I have not figured out how to escape the * character so the script doesn't expand it. More specifically, here's... (9 Replies)
Discussion started by: GKnight
9 Replies

2. Shell Programming and Scripting

How to ignore * (asterisk) in a variable

I am using a shell script to read SQL statements stored in a DB2 table and write them out to a file. The problem I have is that some SQL statements have an "*" in them which gets resolved as the list of files in the current directory when I run the script. How can I prevent the "*" from being... (7 Replies)
Discussion started by: bradtri2
7 Replies

3. AIX

Replace string with asterisk(*) in variable

I was trying to replace a string ( for eg - @@asterisk@@ to * ) in variable using cat $INFILE | while read LINE do stmt1=`echo $LINE | sed 's/@@asterisk@@/\*/g'` stmt=$stmt' '$stmt1 stmt2=`echo $LINE` STATEMENT=$STATEMENT' '$stmt2 done echo 'Statement with sed -- > '... (5 Replies)
Discussion started by: Vaddadi
5 Replies

4. Shell Programming and Scripting

How to assign * asterisk to variable?

How can I assign asterisk to variable I have try a="\* " but I was not succesful :( any idea ? thanks (5 Replies)
Discussion started by: kvok
5 Replies
All times are GMT -4. The time now is 04:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy