script t*
...but I do not want the t* to be expanded out into a list of file
names and nor do I want people to put the t* in quotes such as 't*'.
Can I set options in first line in the script to disable shell globbing
or a later line or will it be done no matter what?
Issue a "set -f" to disable filename generation. That will
disable it once and for all. If you want to disable it only for
the "script" command, then you can only do it with the zsh
shell:
alias 'script=noblog script'
But, in the first place, why don't you want the shell to expand
that glob pattern?
--
Stephane
This is a script that will be used by people who know little about
Unix/Linux and know nothing about shell globbing. I don't want them
setting shell options like that.
> disable it once and for all. If you want to disable it only for
> the "script" command, then you can only do it with the zsh
> shell:
>
> alias 'script=noblog script'
I don't want them setting an alias like that either.
> But, in the first place, why don't you want the shell to expand
> that glob pattern?
Because I will be using it in a case statement as t* or whatever they
typed in. It will be used to select files out of a list and not files
in the current directory.
> --
> Stephane
Then you're stuck.
The best you can do if you can only modify the script (don't
call your script "script" as it is the name of a standard
command) is (inside the script) to have a look at the last line
of the user's shell history file (~/.bash_history) to see what
shell command line was used and this can't be done reliably.
--
Stephane
I thought so :o(
> The best you can do if you can only modify the script (don't
> call your script "script" as it is the name of a standard
> command) is (inside the script) to have a look at the last line
> of the user's shell history file (~/.bash_history) to see what
> shell command line was used and this can't be done reliably.
>
> --
> Stephane
Then I'll have to use an option in the script and prompt for a file
pattern and use that in the case statement.
#!/bin/bash -f
# Script : seldone
# Version : 1.0
# Author : Roland Rashleigh-Berry
# Date : 11-Jan-2005
# Purpose : To select files from donelist.txt
# SubScripts : none
# Notes : none
# Usage : seldone
# seldone -s
#======================================================================
# OPTIONS:
#-opt- -------------------------------description----------------------
# s (switch) selection pattern
#======================================================================
# PARAMETERS:
#-pos- -------------------------------description----------------------
# N/A Do not supply parameters
#======================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description---------------
#
#======================================================================
# Usage message and exit
usage () {
echo "Usage: seldone -s" 1>&2
exit 1
}
# Default is not to prompt for a file pattern
switchs=0
# "case" statement for action to take on selected options
while getopts "s" param ; do
case $param in
"?") # bad option supplied
usage
;;
"s") # (switch) selection pattern
switchs=1
;;
esac
done
# shift to bring first parameter to position 1
shift $(($OPTIND - 1))
# No parameters allowed
if [ $# -gt 0 ] ; then
echo "Error: (seldone) Do not supply any parameters" 1>&2
usage
fi
# if option set then prompt for file pattern else default to *
if [ "$switchs" == "1" ] ; then
echo -n "Enter your file pattern: "
read patt
else
patt=*
fi
# read in donelist.txt and select files that match the pattern
for filename in $(cat donelist.txt | cut -d' ' -f2-) ; do
case "$filename" in
$patt) echo "$filename"
;;
esac
done
I think the globbing actually happens before the script is called,
so whatever you do or set from within the script will be too late.
For any settings to have any effect (no, I can't tell you exactly
which ones) they would have to be set prior to calling the script,
in the environment from which it is called.
Cheers CV
CV wrote:
The simplest solution is to use quotes (single or double) around the
parameter or
put a backslash (\) in front of the wildcard characters, i.e., script
t\*. But if there can
be multiple wildcards in the parameter, quotes are more effective.
Bill Seivert
sei...@pcisys.net
I agree but the users of this script won't remember to do this.
Why don't you put
alias yourscript='noglob yourscript'
in /etc/zshrc?
If your users are not experienced Unix users, they would benefit
from having zsh as their login shell.
--
Stephane
bash is the "official" shell here. I can't change it.
yourscript() {
command yourscript "$@"
set +f
}
alias yourscript='set -f; yourscript'
in:
/etc/bash.bashrc
(your bash may not support system-wide bashrc as it's a compile
time configuration. If so consider using a PROMPT_COMMAND
env var in /etc/profile (not very reliable) or force every
~/.bashrc to source /etc/bash.bashrc)
may work. but beware of command lines like:
cmd1 || yourscript args
that won't work as you expect.
--
Stephane
You can. http://zsh.sunsite.dk/FAQ/zshfaq01.html#l8
--
#!/bin/sh -
set - `type $0` 'tr "[a-zA-Z]" "[n-za-mN-ZA-M]"';while [ "$2" != "" ];do \
shift;done; echo 'frq -a -rc '`echo "$0"| $1 `'>$UBZR/.`rpub signature|'`\
echo $1|$1`'`;rpub "Jr ner fvtangher bs obet. Erfvfgnapr vf shgvyr!"'|$1|sh
If your users are naive about Unix, couldn't you get them to use a
different character than "*" for wildcard, eg "%"? Your script could
then bypass globbing (unless you have files in $PWD called *%* of
course) and process the list as you desire.
--
.
--
BOFH excuse #270:
Someone has messed up the kernel pointers