You guys are conflating two different POSIX shell mechanisms here. One is the arithmetic expansion and the other is command expansion. These are different.
$(()) denotes arithmetic expansion, and $() denotes command expansion.
Shells that support $() or $(()) generally support both. For older shells that do not support these syntaxes, you need to use backticks (`) for command expansion and arithmetic expansion isn't supported. In arithmetic expansion, Corona rightly reports that you do not need $ to expand variables; however, you do need this in command expansion. For example:
However:
OTOH, if we give it an expr command:
We need explicit variable expansion:
BTW, if we want compatibility with older shells that do not support arithmetic expansion, we generally are not going to be able to use new-style command expansion, so we want something like this, instead:
we dont conflating anything.we are talking just arithmetic expansion about all shell variants.
I was referring to mentioned syntax of "$((x+y))" expression gives error on the some older shells..
In addition, I mentioned what i identified a issue that is maybe a bug in ash.
because of it(false statement) does not give any error at try of 3rd.
Hi all,
I got some problems on executing the following scripts.
Scripts:
if ]; then
echo "M${str}O 0 1" >> ${tempFile}
elif ]; then
echo "M${str}O 1 0" >> ${tempFile}
else
echo "M${str}O 0 0" >> ${tempFile}
fi
Error:
"`;' is not expected."
what's the problem? (2 Replies)
I am receiving an elif error on line 13 and I can not figure out the reasoning behind it. I have added the then statement that I was initially missing. Any help would be great.
#The purpose of this script is for the end user to be able to enter a positive number
#User enters a number
NUM=$1... (4 Replies)
Script Gurus,
Need your help in getting this script to come out of logical error : I have pasted the script below: This script finds disk utilzation ... the script is written for both AIX and SUN OS... and option will be given in the initial to select DB or Non DB... its required for my prj...... (1 Reply)
I am getting below error from this code (which is at line 24):
if ] #this is line24 in code
then
mv $File_source_path/$File_name $File_name'_'`date '+%d%m%y'`
Error:
line 24:
Any help with the syntax. I am putting 2 condition with 'AND' clause.
This is bash shell. (2 Replies)
I am in need of some help. I am not an advance scripter or programmer, I have novice knowledge. I cannot get a script to work as expected. The script basically does an FTP (which I have work perfectly) and writes to a log. However, I want the script to echo "Not Connected" if the FTP fails to... (2 Replies)
Hi All,
I write an script will have some functions... I am getting elif not expected error..
Even tried by using set -x for debug but no use..
Could you please help me out in this
Variables
....
....
....
TEST_SRC()
{
cat ${filesrc} >> ${filetgt}
if ]; then
echo... (12 Replies)
Hi there, new to this forum and I recently encounter this problem:
I tried to use if-elif loop in a while-read loop, something like this:
#!/bin/bash
while read myline1 myline2
do
if ; then
echo "Successful!"
elif ; then
echo "Failed"
fi
done < $1
Input file looks like this:
200... (13 Replies)
Hi all,i have configured the following script to check if the file exists or not,
#!/bin/sh
sleep 30
{
FILEFULL=$1`date +$2`*
if ;
then
echo $FILEFULL exist
else
echo "$FILEFULL File not Found" | mail -s 'server' myaccount@mydomain.com
fi
}
but i have a problem, i need to... (2 Replies)
Hello all,
I have a scenario where I take user input values and accordingly take actions
say I run a script with
sh scriptname -x GB -e txt (txt can also be text)
I have used if clause for the first input (-x GB)and it is working fine
Now for second the scenario is
if
then
echo... (3 Replies)
Hello experts,
I am having problems with ELIF.
Please see the below code :
read a;
read b;
read c;
if || || ; then
echo "EQUILATERAL"
elif || || ; then
echo "SCALENE"
else
echo "ISOSCELES"
fi
This code works fine for the EQUILATERAL case but fails completely for the... (5 Replies)
Discussion started by: H squared
5 Replies
LEARN ABOUT SUSE
wordfree
WORDEXP(3) Linux Programmer's Manual WORDEXP(3)NAME
wordexp, wordfree - perform word expansion like a posix-shell
SYNOPSIS
#include <wordexp.h>
int wordexp(const char *s, wordexp_t *p, int flags);
void wordfree(wordexp_t *p);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
wordexp(), wordfree(): _XOPEN_SOURCE
DESCRIPTION
The function wordexp() performs a shell-like expansion of the string s and returns the result in the structure pointed to by p. The data
type wordexp_t is a structure that at least has the fields we_wordc, we_wordv, and we_offs. The field we_wordc is a size_t that gives the
number of words in the expansion of s. The field we_wordv is a char ** that points to the array of words found. The field we_offs of type
size_t is sometimes (depending on flags, see below) used to indicate the number of initial elements in the we_wordv array that should be
filled with NULLs.
The function wordfree() frees the allocated memory again. More precisely, it does not free its argument, but it frees the array we_wordv
and the strings that points to.
The string argument
Since the expansion is the same as the expansion by the shell (see sh(1)) of the parameters to a command, the string s must not contain
characters that would be illegal in shell command parameters. In particular, there must not be any unescaped newline or |, &, ;, <, >, (,
), {, } characters outside a command substitution or parameter substitution context.
If the argument s contains a word that starts with an unquoted comment character #, then it is unspecified whether that word and all fol-
lowing words are ignored, or the # is treated as a non-comment character.
The expansion
The expansion done consists of the following stages: tilde expansion (replacing ~user by user's home directory), variable substitution
(replacing $FOO by the value of the environment variable FOO), command substitution (replacing $(command) or `command` by the output of
command), arithmetic expansion, field splitting, wildcard expansion, quote removal.
The result of expansion of special parameters ($@, $*, $#, $?, $-, $$, $!, $0) is unspecified.
Field splitting is done using the environment variable $IFS. If it is not set, the field separators are space, tab and newline.
The output array
The array we_wordv contains the words found, followed by a NULL.
The flags argument
The flag argument is a bitwise inclusive OR of the following values:
WRDE_APPEND
Append the words found to the array resulting from a previous call.
WRDE_DOOFFS
Insert we_offs initial NULLs in the array we_wordv. (These are not counted in the returned we_wordc.)
WRDE_NOCMD
Don't do command substitution.
WRDE_REUSE
The argument p resulted from a previous call to wordexp(), and wordfree() was not called. Reuse the allocated storage.
WRDE_SHOWERR
Normally during command substitution stderr is redirected to /dev/null. This flag specifies that stderr is not to be redirected.
WRDE_UNDEF
Consider it an error if an undefined shell variable is expanded.
RETURN VALUE
In case of success 0 is returned. In case of error one of the following five values is returned.
WRDE_BADCHAR
Illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }.
WRDE_BADVAL
An undefined shell variable was referenced, and the WRDE_UNDEF flag told us to consider this an error.
WRDE_CMDSUB
Command substitution occurred, and the WRDE_NOCMD flag told us to consider this an error.
WRDE_NOSPACE
Out of memory.
WRDE_SYNTAX
Shell syntax error, such as unbalanced parentheses or unmatched quotes.
VERSIONS
wordexp() and wordfree() are provided in glibc since version 2.1.
CONFORMING TO
POSIX.1-2001.
EXAMPLE
The output of the following example program is approximately that of "ls [a-c]*.c".
#include <stdio.h>
#include <stdlib.h>
#include <wordexp.h>
int
main(int argc, char **argv)
{
wordexp_t p;
char **w;
int i;
wordexp("[a-c]*.c", &p, 0);
w = p.we_wordv;
for (i = 0; i < p.we_wordc; i++)
printf("%s
", w[i]);
wordfree(&p);
exit(EXIT_SUCCESS);
}
SEE ALSO fnmatch(3), glob(3)COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2008-07-14 WORDEXP(3)