07-07-2008
Bash: evaluating $? variable (if statement)
Hello, i'm unable to write a correct if... statement to evaluate the $? variable.
Could anybody send to me an example? for example, this lines of code didn't work...
if [ $? eq 0 ]; then
etc etc
if [ $? == 0 ]; then
etc etc
Thank you in advanced.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have the following requirement.
V="First"
R="V"
echo $$R
The output should be First. How do i achieve this.
how do we evaluate the $R and evaluate it to $V as $R contains V
and $V is First.
Thanks
Vijay (2 Replies)
Discussion started by: vijaykrc
2 Replies
2. UNIX for Dummies Questions & Answers
I want to combine 2 conditional statements by using -o in bash, but it won't work.
if ; then
echo "The number needs to be between 0 and $nr"
fi
Each time i execute the file it says:
./selectCitaat: line 10: syntax error near unexpected token `$1' (3 Replies)
Discussion started by: doc.arne
3 Replies
3. Shell Programming and Scripting
Does anyone know of a way to force a variable name held in another variable to return the value of the first variable? Best if I give an example, that does not work:
/usr/local/bin >cat mike.sh
NUM1ref=16
NUM2ref=32
echo "=============="
for VAR in NUM1 NUM2
do
XXXX=${VAR}ref
echo $XXXX... (4 Replies)
Discussion started by: mikejordan
4 Replies
4. Shell Programming and Scripting
Hi there, i think im getting myself a little confused and need some help :wall:
I am reading in a bunch of variables to my script from an external file and need to validate that a value has been set for each
so if you can imagine, the user is required to pass in 4 values... (3 Replies)
Discussion started by: rethink
3 Replies
5. UNIX for Dummies Questions & Answers
So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated.
Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies
6. Shell Programming and Scripting
Hi I need a script with an if statement that goes.
I need it to search through all files within a directory with the extension .test if it finds the string '71502FSC1206' then do
sed 's/71502FSC1206/\n&/g' > send.test
If it finds the string '715MCH' or '715JAC' then I need it to move the... (1 Reply)
Discussion started by: firefox2k2
1 Replies
7. UNIX for Dummies Questions & Answers
Hey guys,
Currently trying to write a wee script that runs only when logged in as one of two users. The rest of the script is working fine, but no matter what user I try to run it as, it always fails! This is the puzzling part:if ]; then
echo "Run script as admin "
exit 1
else... (6 Replies)
Discussion started by: jimbob01
6 Replies
8. Shell Programming and Scripting
Hi Gurus,
I have the below BASH code which does not works for upper case alphabets except Z (upper case Z).
What may be the reason. Also escape sequences like \n, \t, \b, \033(1m \033(0m (For bold letter) are not working.
case $var in
)
echo "Lower case alphabet"
;;
... (7 Replies)
Discussion started by: GaneshAnanth
7 Replies
9. Shell Programming and Scripting
I have the following code in bash, however "set red frmt" is not displayed.
echo "iarg_rd = $iarg_rd"
iarg_rd="2"
if ; then
echo "Hello World"
fi
if ; then
frmt="${gap}${!frmt_titl_yl}"
elif ; then
frmt="${gap}${!frmt_titl_bk}"
elif ; then
echo... (2 Replies)
Discussion started by: kristinu
2 Replies
10. UNIX for Dummies Questions & Answers
Hi all,
i need a equivalent for the statement i run in bash, so it would also run in other shells. Specially i need it for ksh to run on AIX.
Here the statements:
exec > >(tee -a $log)
exec 2> >(tee -a $log >&2)
Thanks. (5 Replies)
Discussion started by: Kosak
5 Replies
LEARN ABOUT DEBIAN
preprocess
PREPROCESS(1) General Commands Manual PREPROCESS(1)
NAME
preprocess - Preprocess a file.
SYNOPSIS
preprocess [options...] infile
DESCRIPTION
Preprocess is like a typical C preprocessor, but it extends to multiple languages. Languages for which it works include: C++, Python, Perl,
Tcl, XML, JavaScript, CSS, IDL, TeX, Fortran, PHP, Java, Shell scripts (Bash, CSH, etc.) and C#. Preprocess is usable both as a command
line app and as a Python module.
OPTIONS
-h, --help
Print help text and exit.
-V, --version
Print the version info and exit.
-v, --verbose
Give verbose output for errors.
-o outfile
Write output to the given file instead of to stdout.
-f, --force
Overwrite given output file. Otherwise an IOError will be raised if outfile already exists.
-D define
Define a variable for preprocessing. define can simply be a variable name (in which case it will be true) or it can be of the form
var=val. An attempt will be made to convert val to an integer so "-D FOO=0" will create a false value.
-I dir Add a directory to the include path for #include directives.
-k, --keep-lines
Emit empty lines for preprocessor statement lines and skipped output lines. This allows line numbers to stay constant.
-s, --substitute
Substitute defines into emitted lines. By default substitution is NOT done because it currently will substitute into program
strings.
MODULE USAGE
from preprocess import preprocess
preprocess(infile, outfile=sys.stdout, defines={}, force=0,
keepLines=0, includePath=[], substitute=0)
The <infile> can be marked up with special preprocessor statement lines of the form:
<comment-prefix> <preprocessor-statement> <comment-suffix>
where the <comment-prefix/suffix> are the native comment delimiters for that file type.
EXAMPLES
HTML (*.htm, *.html) or XML (*.xml, *.kpf, *.xul) files:
<!-- #if FOO -->
...
<!-- #endif -->
Python (*.py), Perl (*.pl), Tcl (*.tcl), Ruby (*.rb), Bash (*.sh), or make ([Mm]akefile*) files:
# #if defined('FAV_COLOR') and FAV_COLOR == "blue"
...
# #elif FAV_COLOR == "red"
...
# #else
...
# #endif
C (*.c, *.h), C++ (*.cpp, *.cxx, *.cc, *.h, *.hpp, *.hxx, *.hh), Java (*.java), PHP (*.php) or C# (*.cs) files:
// #define FAV_COLOR 'blue'
...
/* #ifndef FAV_COLOR */
...
// #endif
Fortran 77 (*.f) or 90/95 (*.f90) files:
C #if COEFF == 'var'
...
C #endif
PREPROCESSOR SYNTAX
Valid statements:
#define <var> [<value>]
#undef <var>
#ifdef <var>
#ifndef <var>
#if <expr>
#elif <expr>
#else
#endif
#error <error string>
#include "<file>"
where <expr> is any valid Python expression.
The expression after #if/elif may be a Python statement. It is an error to refer to a variable that has not been defined by a -D option or
by an in-content #define.
Special built-in methods for expressions:
defined(varName) Return true if given variable is defined.
TIPS
A suggested file naming convention is to let input files to preprocess be of the form <basename>.p.<ext> and direct the output of prepro-
cess to <basename>.<ext>, e.g.:
preprocess -o foo.py foo.p.py
The advantage is that other tools (esp. editors) will still recognize the unpreprocessed file as the original language.
AUTHORS
Trent Mick <trentm@gmail.com>
This manual page was written by Johannes Ring <johannr@simula.no> for the Debian GNU/Linux system (but may be used by others).
PREPROCESS(1)