matteocorti / bashcritic Goto Github PK
View Code? Open in Web Editor NEWbashcritic is a tool to check shell scripts for common pitfalls
License: GNU General Public License v3.0
bashcritic is a tool to check shell scripts for common pitfalls
License: GNU General Public License v3.0
Original reporter: [email protected]
wait "$pid"
may block if the process of $pid pid had terminated before the
wait command was run in some shells (even though they shouldn't
as per latest version of POSIX).
Original reporter: [email protected]
unset is not in every Bourne shell
Original reporter: [email protected]
Sort by name or severity
Original reporter: [email protected]
check that the first argument to printf is not variable.
printf "$var"
should be
printf %s "$var"
printf "$pattern" "$@"
is probably OK, for more than one arg, it's hard to tell what
the programmer's intent was.
Original reporter: [email protected]
From: http://groups.google.com/group/comp.unix.shell/browse_frm/thread/d57685ad71013736#
In POSIX shell, you can't guarantee the behavior of "[" if there
are more than three arguments, so -a and -o should be avoided
and several "[" command run instead. It's unlikely to cause
problem in your case, but it's a good habit to have in any case.
Original reporter: [email protected]
type is required by Unix but not POSIX and is not in every
Bourne shell and in every POSIX shell (see posh).
Original reporter: [email protected]
Most Bourne builtins don't support "--"
Original reporter: [email protected]
echo
should be banned except maybe with non-variable arguments that
don't start with "-" and don't contain backslashes.
echo -n and echo -e are neither portable nor standard.
even with one same shell (especially for ksh93 and bash), echo's
behavior may vary depending on the environment.
Original reporter: [email protected]
$((...)) is POSIX but not Bourne
Original reporter: [email protected]
$"..." is ksh93/bash specific (and handled differently)
Original reporter: [email protected]
$PWD is POSIX but not Bourne (most shells are not POSIX in that
they don't ignore the value of the $PWD env var, you need to do
a pwd -P > /dev/null at the start of your script to fix its
value).
Original reporter: [email protected]
check for [a-z] and [A-Z] which depend on the locale and substitute with [[:lower:]] and [[:upper:]]
Original reporter: [email protected]
Do not check comments
Original reporter: beuzoxnl
lzxxkfvg [URL=http://emhhctjj.com]avoawfio[/URL] jovcpgig http://pijgyplv.com kbvvicdw tsgwkndg
Original reporter: [email protected]
${var/../..} ${var//../..} are ksh93/zsh/bash specific
Original reporter: [email protected]
Try to automatically detect the type of the shell by the shebang
Original reporter: [email protected]
arrays are bash/ksh/zsh specific (and handled differently in those shells).
Original reporter: [email protected]
brace expansion is not Bourne ({a,b})
Original reporter: [email protected]
Original reporter: [email protected]
Why do I lose the value of global variables that are set in a loop.
Given the following program
#!/bin/sh
x="this is the initial value of x"
cat dataFile | while read line;do
x="$line"
done
echo x = $x
You may get the following for output
x = this is the initial value of x
This is because in the Bourne shell redirected control structures
run in a subshell, so the value of x only gets changed in the
subshell, and is lost when the loop ends.
In other shells the same result may be seen because of the way
pipelines are handled. In shells other than ksh (not pdksh) and
zsh elements of a pipeline are run in subshells. In ksh and zsh,
the last element of the pipeline is run in the current shell.
An alternative for non-Bourne shells is to use redirection
instead of the pipeline
#!/bin/sh
x="this is the initial value of x"
while read line;do
x="$line"
done < dataFile
echo x = $x
With a Bourne shell you need to reassign file descriptors, so no
pipline or redirection in the loop is involved.
exec 3<&0 # save stdin
exec < file
while read line; do
x=$line
done
exec 0<&3 # restore stdin
Note that putting #!/bin/sh at the top of a script doesn't
guarantee you're using the Bourne shell. Some systems link /bin/sh
to some other shell. Check your system documentation to find out
what shell you're really getting in this case.
Original reporter: [email protected]
An error in a rule definition (function) should not stop the program execution but just give an error message and continue.
Original reporter: [email protected]
Check for RCS keyword substitutions (see Perl::Critic)
Original reporter: [email protected]
select is ksh/bash/zsh specific
and is of no use. as you can use printf and read.
Original reporter: [email protected]
[ -n $VAR1 -a -n $VAR2 ]
does not work if $VAR1 or $VAR2 was never defined. Use
[ -n "$VAR1" -a -n "$VAR2" ]
Note: check this on comp.unix.shell first
Original reporter: [email protected]
When looking for a pattern bashcritic does not separate words.
Example looking for which it will also complain about
my_nice_which_command
Original reporter: [email protected]
command, alias, readonly are not Bourne
Original reporter: [email protected]
$RANDOM
$SECONDS are bash/ksh/zsh specific. Use awk's rand() for
randomness.
Original reporter: [email protected]
check if sed is used with non-standard options as -r GNU or -E BSD(?)
Original reporter: [email protected]
double quotes should be escaped in double quoted backticks:
echo "echo \"a b\"
"
Original reporter: [email protected]
tilde expansion is not Bourne
Original reporter: [email protected]
functions and comments were not supported in very early versions of the Bourne shell
Original reporter: [email protected]
^ should be quoted (as required by POSIX and it's special in
Bourne and zsh).
Original reporter: [email protected]
${var❌x} is ksh93/bash specific
Original reporter: [email protected]
$RANDOM
$SECONDS are bash/ksh/zsh specific. Use awk's rand() for
randomness.
Original reporter: [email protected]
Implement an internal routine to check program options.
Something like
check_option('sed','-r') to check if the script uses sed with the GNU -r option
Original reporter: anonymous
I just download and try bashcritic 0.3.2 , and I got the following perl error
Can't use string ("BASH") as an ARRAY ref while "strict refs" in use at /usr/bin/bashcritic line 192.
Original reporter: [email protected]
var=$, var=$@ are not handled the same in all shells if the
first char of IFS is not " ".
var="$" should be OK (except that the Bourn shell always joins
with space).
Original reporter: [email protected]
Each rule processes the whole file with the result that error messages are grouped by rule.
Errors should be sorted by line number so that a sequential processing is possible.
Original reporter: favlhueh
[URL=http://blyuxjiu.com]znqyjfag[/URL] kwjvwjkq http://ojjrnagv.com rzwvazbv bglexkad jxpdpjpy
Original reporter: [email protected]
[[iframe http://player.youku.com/embed/XNzA4NjczMzQ4 height="498" width="510"]][[iframe http://www.youtube.com/embed/gSWg2piAoOs height="315" width="560"]]
Old age is one sure thing on this earth. Whether we like it or not, all of us will undergo the process of aging. Starting at the age of 35, the signs of aging are starting to show and these are one dry Skin care concern of most people. They would do everything in order to get rid of them. But due to the advancement of technology, there are many ways to fight the signs of aging. There are people who are willing to undergo surgical operations only to get rid of the signs of aging. But there are also others who choose the safest way and that is by using those effective anti aging skin care products.
The best anti Wrinkle Cream for men will be made with the latest technology. It will deliver the necessary nutrients through your skin's layers to heal your aging body. As each cell heals the body begins to work again at full capacity.
Price is not the true factor to determine a cream's quality. People usually believe that expensive creams are the answer to skin's problems. So, when your friends suggest you a costly cream recently arrived in the store, you rush to buy it with hopes of making your skin beautiful. In fact, you boast of this lavish Wrinkle Cream Reviews in front of your neighbors and colleagues.
When you want your skin to look softer and to take years off of your appearance, you can use the same product for both - an Best Anti-Aging Serums treatment. But soft skin and youthful appearance are just two of the benefits of using a serum. There are plenty more.
Never think twice of following these tips when you have this goal of fighting away wrinkles. These tips are your only and your best resource when finding the best anti wrinkle product today. Remember that you have many options when fighting away the annoying wrinkles on your face but there is only one single best product that can totally give you fast and long-term relief when it comes to this ugly aging sign.
Original reporter: [email protected]
cd -- "$var"
should be
cd -P -- "$var" (except in the Bourne shell)
Original reporter: [email protected]
$'...' is ksh93/bash/zsh specific (and handled differently)
use printf %b instea
Original reporter: [email protected]
command -v/-V are optionnal in POSIX
Original reporter: [email protected]
Check if it is possible to make Makefile.PL (and Makefile) put the right shebang in the script
Original reporter: [email protected]
Check for trailing spaces
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.