The OpenNET Project / Index page

[ новости /+++ | форум | wiki | теги | ]

Поиск:  Каталог документации

3.26. Gotchas

Assigning reserved words or characters to variable names.
# Causes problems.
# Also problems. Variable names starting with a digit are reserved by the shell.
# Try var2=_23skidoo. Starting variables with an underscore is o.k.
# Causes even worse problems.

Using a hyphen or other reserved characters in a variable name.
# Use 'var_1' instead.

Using white space inappropriately (in contrast to other programming languages bash can be finicky about white space).
var1 = 23
# 'var1=23' is correct.
let c = $a - $b
# 'let c=$a-$b' or 'let "c = $a - $b"' are correct.
if [ $a -le 5]
# 'if [ $a -le 5 ]' is correct.

Using uninitialized variables (that is, using variables before a value is assigned to them). An uninitialized variable has a value of "null", not zero.

Mixing up = and -eq in a test. Remember, = is for comparing literal variables and -eq is for numbers.
	if [ $a = 273 ] # Wrong!
	if [ $a -eq 273 ] # Correct.

Commands issued from a script may fail to execute because the script owner lacks execute permission for them. If a user cannot invoke a command from the command line, then putting it into a script will likewise fail. Try changing the attributes of the command in question, perhaps setting the suid bit (as root, of course).

Using bash version 2 functionality (see below) in a script headed with #!/bin/bash may cause a bailout with error messages. Your system may still have an older version of bash as the default installation. Try changing the header of the script to #!/bin/bash2.

Making scripts "suid" is generally a bad idea, as it may compromise system security. Administrative scripts should be run by root, not regular users.

Inferno Solutions
Hosting by

Закладки на сайте
Проследить за страницей
Created 1996-2022 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру