09-11-2002
Wildcards and quoting
Hi All
In a script, I want a user to enter 4 characters, these can be a mix of letters (uppercase and lowercase) and numbers.
In this example $var represents what the user has entered.
eg $var can be A9xZ, 3DDL, bbHp .........etc
I need to check that the user has only entered characters so I added the following code:
# Check for invalid characters
echo "$var" | grep [^a-zA-Z0-9] >/dev/null
if [ $? -eq 0 ]
then
echo "$var is not valid."
fi
This appears to work ok unless the user enters a wildcard character.
For example if the user enters bin*, the script expands the * and makes $var equal to all files in the current directory which start with bin.
So $var is "bin bindir binary"
My question is how can I process $var literally as "bin*" in the above grep statement?
Thanks for your help
Helen
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have trouble with quotations of the M4 preprocessor.
I want to write a basic makro that removes all spaces and newlines at the end and at the beginning of a string.
I tried this:
define(`TRIM_END', `patsubst(`$1', `\(\\n\| \)*$', `')')
define(`TRIM', `patsubst(`TRIM_END(`$1')',... (0 Replies)
Discussion started by: hindman
0 Replies
2. Shell Programming and Scripting
Can someone explain the following? I can use find on *.pm without quotes, but find on *.pl makes on error, I need quotes for the second version. What's up with that?
$find -name *.pm
./tieProxyStatus/Status.pm
$find -name *.pl
find: paths must precede expression
Usage: find
$find... (2 Replies)
Discussion started by: tphyahoo
2 Replies
3. Shell Programming and Scripting
can somebody help, what quote i should use in below statement or what wrong of it ?
the 1st (*) is a char, the 2nd and 3rd (*) is a wildcard
if ] && ] && ]
................^ .............^
then
echo "ok"
fi
thanks in advance. (2 Replies)
Discussion started by: 3Gmobile
2 Replies
4. Shell Programming and Scripting
The block below isn't a surprise:$ ls
file1 file2 file3
$ x=*
$ echo $x
file1 file2 file3
$ echo '$x'
$x
$ echo "$x"
*
$But I found this block a bit bewildering:$ echo $x'
>'
*
$I'm wondering why substitution wasn't performed on the $x, since it was unquoted (as far as I can tell).... (5 Replies)
Discussion started by: na5m
5 Replies
5. Shell Programming and Scripting
hi guys, i have a question related to quoting but i am not sure how to formulate it...
lets say we want to simulate the following shell actions
cd ~/project-dir
ctags /home/work/folder1/*.sh /home/work/folder2/*.sh /home/work/folder3/*.sh
so i make the following script
buidtags.sh
... (2 Replies)
Discussion started by: aegis
2 Replies
6. Shell Programming and Scripting
(no, i can't switch shells, although i'd love to. yes, i have read http://www.grymoire.com/Unix/CshTop10.txt.)
i finally managed to get an alias working the way i want it to, but i don't understand how one part of it works (highlighted in red):
alias log ' \\
set x=`echo \!:1 | /bin/sed... (1 Reply)
Discussion started by: acheong87
1 Replies
7. Shell Programming and Scripting
I have this data how do i add ' ' to them like '-AAL00L' , '-BBE4577' , 'ABC'
-AAL00L
-BBE4577
ABC (5 Replies)
Discussion started by: dinjo_jo
5 Replies
8. Shell Programming and Scripting
Hi,
I have got a file comp_data containing the below data :
38232836|9302392|49
39203827|8203203,3933203|52
72832788|567,3245,2434324|100
This file can have many rows like shown above. I want the values separated by "," in second column(taking "|" as delimiter) to be in quotes. These... (2 Replies)
Discussion started by: msabhi
2 Replies
9. Shell Programming and Scripting
I am at a loss on this one. I am trying to run this command on a bunch of (OS 10.7.4) macs:osascript -e "tell application \"System Events\" to return name of every process whose frontmost is true"
On some, it works fine. On others, I get this error:
I have also tried (note the single quotes):... (3 Replies)
Discussion started by: nextyoyoma
3 Replies
10. Shell Programming and Scripting
I am trying to write a BASH script that will prompt a user to enter a number of days, then calculate the date.
My problem is the date command uses single or double quotes. For Example..
date -d "7 days"
Here is an example of some same code I am trying to work through.
echo "when do you... (4 Replies)
Discussion started by: javajockey
4 Replies
LEARN ABOUT ULTRIX
qmail-pw2u
qmail-pw2u(8) System Manager's Manual qmail-pw2u(8)
NAME
qmail-pw2u - build address assignments from a passwd file
SYNOPSIS
qmail-pw2u [ -/ohHuUC ] [ -cchar ]
DESCRIPTION
qmail-pw2u reads a V7-format passwd file from standard input and prints a qmail-users-format assignment file.
A V7-format passwd file is a series of lines. Each line has the format
user:password:uid:gid:gecos:home:shell
where user is an account name, uid and gid are the user id and group id of that account, and home is the account's home directory. pass-
word, gecos, and shell are ignored by qmail-pw2u.
If you put the output of qmail-pw2u into /var/lib/qmail/users/assign, and then run qmail-newu, qmail-lspawn will obey the assignments
printed by qmail-pw2u. WARNING: After changing any users, uids, gids, or home directories in your passwd file, you must run qmail-pw2u and
qmail-newu again if you want qmail-lspawn to see the changes.
RULES
By default, qmail-pw2u follows the same rules as qmail-getpw. It skips user if (1) uid is zero, (2) home does not exist, (3) user does not
own home, or (4) user contains uppercase letters. It then gives each remaining user control over the basic user address and all addresses
of the form user-anything. A catch-all user, alias, controls all other addresses.
You may change these rules by setting up files in /var/lib/qmail/users:
include
Allowed users, one per line. If include exists, and user is not listed in include, user is ignored.
exclude
Ignored users, one per line. If exclude exists, and user is listed in exclude, user is ignored.
mailnames
Replacement names for users. Each line has the form
user:mailname1:mailname2:...
The addresses mailname1 and mailname1-ext and mailname2 and so on will be delivered to user.
WARNING: The addresses user and user-ext will not be delivered to user unless user is listed as one of the mailnames.
A line in mailnames is silently ignored if the user does not exist.
subusers
Extra addresses. Each line has the form
sub:user:pre:
sub will be handled by home/.qmail-pre, where home is user's home directory; sub-ext will be handled by home/.qmail-pre-ext.
append Extra assignments, printed at the end of qmail-pw2u's output.
OPTIONS
-o (Default.) Skip user if home does not exist (or is not visible to qmail-pw2u). Skip user if home is not owned by user.
-h Stop if home does not exist. This is appropriate if every user is supposed to have a home directory. Skip user if home is not
owned by user.
-H Do not check the existence or ownership of home.
-U (Default.) Skip user if there are any uppercase letters in user.
-u Allow uppercase letters in user.
-cchar Use char as the user-extension delimiter in place of -.
-C Disable the user-extension mechanism.
-/ Use home/.qmail-/... instead of home/.qmail-...
SEE ALSO
qmail-users(5), qmail-lspawn(8), qmail-newu(8), qmail-getpw(8)
qmail-pw2u(8)