Your question cannot be answered quite generally. Some comments though. On my version of bash (3.1.17(1)-release), your command doesn't have the desired output even when run from the command line; the same with zsh. So presumably something is fishy about your command. I don't know what "##+(0)" is suppoed to accomplish, but "#0" succeeds in removing one leading zero. This show a way to remove arbitrary numbers of zeros.
If there really is a difference between the behavior on the command line and from a script, then most likely the script uses a different interpreter (different bash version, bash instead of zsh) or different shell options (try running shopt
). The latter difference might be the result of your interactive shell sourcing $HOME/.bashrc
and $HOME/.profile
whereas scripts generally don't. That shouldn't affect environment variables, as they're inherited if exported, but it should affect shell options, which need to be set in every shell.
Citing man 7 glob
:
An expression "[!...]" matches a single character, namely any character
that is not matched by the expression obtained by removing the first '!' from it.
(Thus, "[!]a-]" matches any single character except ']', 'a' and '-'.)
Emphasis on the single character part here, []
can not be used for whole strings in Bash Pattern Matching.
bash
's Brace Expansion can be used to match strings, however there is no way (I know of) to negate them. E.g.
1.{gif,csv,mp3}
is expanded to
1.gif 1.csv 1.mp3
no matter whether these files exist.
As wchargin pointed out shopt
can be used to enable extended pattern matching operators, one of them being !()
. After running shopt -s extglob
, e.g.
1.!(gif|csv|mp3)
is expanded to
1.jpg 1.bmp 1.png
if those files exist in the current directory. For more read man bash
(section EXPANSION/Pathname Expansion) and Pathname expansion (globbing).
For what you're trying to do I'd always use find
, which offers the negation and much more, e.g. in the following way:
find . -maxdepth 1 -type f ! -name "*.gif" -a ! -name "*.csv" -a ! -name "*.mp3"
This just lists the findings, if you want to remove them just append the -delete
option to the end of the command. As always with removing actions: Always check carefully first.
find
offers a ton of useful options very well explained by man find
.
Best Answer
It's a synonym of the builtin
source
. It will execute commands from a file in the current shell, as read fromhelp source
orhelp .
.In your case, the file
/etc/vz/vz.conf
will be executed (very likely, it only contains variable assignments that will be used later in the script). It differs from just executing the file with, e.g.,/etc/vz/vz.conf
in many ways: the most obvious is that the file doesn't need to be executable; then you will think of running it withbash /etc/vz/vz.conf
but this will only execute it in a child process, and the parent script will not see any modifications (e.g., of variables) the child makes.Example:
Hope this helps.