Making a variable equal a pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Making a variable equal a pattern
# 1  
Old 03-05-2004
Question Making a variable equal a pattern

Hi,

I would like to assign a pattern to a variable eg test8* or abc[123] etc

The problem I have is that when I assign the pattern to the variable, if any files within the current directory match the pattern then the variable will be evaluated to equal the filenames rather than the literal pattern.

eg. if I do var='test8*' then echo $var, it may come back with

test81 test8234 test8zyx

when I actually would like the value to be

test8*

I have tried 'escaping' the * and using various quotations but have not succeded. Can anyone offer me some advice please?

Many thanks
Helen Smilie
# 2  
Old 03-05-2004
.....

Last edited by druuna; 05-21-2009 at 10:14 AM..
druuna
# 3  
Old 03-08-2004
Re: Making a variable equal a pattern

Quote:
Originally posted by Bab00shka
eg. if I do var='test8*' then echo $var, it may come back with

test81 test8234 test8zyx

when I actually would like the value to be

test8*
I think the problem does not have to do with assigning the variable, but with echoing it back. Try this:

> var=s* (or var='s*')
> echo "$var"

The quotes should prevent the contents of the variable from being interpreted as commands... Smilie
# 4  
Old 03-08-2004
Thank-you both for your replies, the echo "$var" works fine.

Cheers
Helen Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with making the output of a command a variable

I'm writing a script that goes something like this: #!/bin/bash zenity --list --checklist --title="Choose Packages to Install" --width="1000" --height="400" \ --column="Select" --column="Package Name" --column="Description" \ GIMP=$( " " GIMP "GIMP is a free and open source photo editor." ... (1 Reply)
Discussion started by: Defunct_Lizard
1 Replies

2. Shell Programming and Scripting

How to delete all lines before a particular pattern when the pattern is defined in a variable?

I have a file Line 1 a Line 22 Line 33 Line 1 b Line 22 Line 1 c Line 4 Line 5 I want to delete all lines before last occurrence of a line which contains something which is defined in a variable. Say a variable var contains 'Line 1', then I need the following in the output. ... (21 Replies)
Discussion started by: Soham
21 Replies

3. Shell Programming and Scripting

Variable equal to zero Linux 2.6.32-300.39.2.el

friends as I can query for a variable that is zero, from a shell ?? (3 Replies)
Discussion started by: tricampeon81
3 Replies

4. Shell Programming and Scripting

Pattern match exclusive return pattern/variable

I have an application(Minecraft Server) that generates a logfile live. Using Crontab and screen I send a 'list' command every minute. Sample Log view: 2013-06-07 19:14:37 <Willrocksyea1> hello* 2013-06-07 19:14:41 <Gromden29> hey 2013-06-07 19:14:42 Gromden29 lost connection:... (1 Reply)
Discussion started by: gatekeeper258
1 Replies

5. Shell Programming and Scripting

awk to print record not equal specific pattern

how to use "awk" to print any record has pattern not equal ? for example my file has 5 records & I need to get all lines which $1=10 or 20 , $2=10 or 20 and $3 greater than "130302" as it shown : 10 20 1303252348212B030 20 10 1303242348212B030 40 34 1303252348212B030 10 20 ... (14 Replies)
Discussion started by: arm
14 Replies

6. UNIX for Dummies Questions & Answers

Help making manipulable variable

Hello, I'm a newbie in C, but i'm trying to make a file to configurate/manipulate variables of a C code. I tried using int and extern int throught a header or another C code but it doesn't seems to work (even throught the makefile). I also tried (with XML) to put a data structure to hold the... (4 Replies)
Discussion started by: Weavel37
4 Replies

7. Shell Programming and Scripting

sed to replace the matching pattern with equal number of spaces

Hi I have written a shell script which used sed code below sed -i 's/'"$Pattern"'/ /g' $FileName I want to count the length of Pattern and replace it with equal number of spaces in the FileName. I have used $(#pattern) to get the length but could not understand how to replace... (8 Replies)
Discussion started by: rakeshkumar
8 Replies

8. Shell Programming and Scripting

weird equal variable issue

I run this #!/bin/bash cron=$(ps aux | grep crond | grep -v grep | grep -o crond| uniq) echo "cron :$cron:" if ; then echo "OK: crond service running fine on `hostname`" exit 2 else echo "CRITICAL: crond service not running on `hostname`" exit 0... (2 Replies)
Discussion started by: anil510
2 Replies

9. Shell Programming and Scripting

Making script show command (e.g. copy) being executed and variable substitution?

When script is running you only see when some of the commands are not successfull. Is there a way to see which command are executed and to show the substitution of variables as every line is executed ? (3 Replies)
Discussion started by: gr0124
3 Replies

10. UNIX for Dummies Questions & Answers

making a variable as string

I am evaluating a variable from a database and storing it as inside. The value of the variable is alpha numeric.How can i make this a string type.Any functions for the same. (1 Reply)
Discussion started by: dr46014
1 Replies
Login or Register to Ask a Question