Sponsored Content
Top Forums UNIX for Beginners Questions & Answers [BASH] eval command not expanding variables as expected. Post 303041177 by nezabudka on Saturday 16th of November 2019 11:10:40 AM
Old 11-16-2019
probably
Code:
shopt -s extquote

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

expanding dotted paths to absolute ones in bash or sh

I have a little script to help me manage a gallery of image files. It makes symbolic links to every file in and below the current directory, placing them in a target directory which is passed to the script as a parameter. Unfortunately, the script pukes when I pass a parameter that contains... (4 Replies)
Discussion started by: TanRanger
4 Replies

2. UNIX for Advanced & Expert Users

Expanding Variables in User Input

If have var='$variable' how can I expand $variable. I have tried many thing like duble quotes/braces etc, but nothing worked. I need the solution ASAP. (2 Replies)
Discussion started by: Bsk
2 Replies

3. UNIX for Dummies Questions & Answers

Expanding variables with Ed Bash 3.2.33

Hi, The following code finds the line containing fruits in test.txt and replaces instances of apple with banana. ed -s test.txt <<< $'/fruits/s/apple/banana/g\nw' What I want to do is put variables in the place of fruits, apple and banana. I have tried replacing ' with " to get... (2 Replies)
Discussion started by: de_la_espada
2 Replies

4. Shell Programming and Scripting

Dynamic variables and eval

Hi, I need some direction with the following. The below code is semi-psuedo code which will hopefully make it easier to understand what I am trying to achieve: for i in `echo ${testarray }` do let c=c+1 eval "first$c=$i" while... (4 Replies)
Discussion started by: yonderboy
4 Replies

5. Shell Programming and Scripting

dynamic variables - eval - expand etc.

Hello, so i'm making a script, using dynamic variables and trying to expand them. So far it hasn't worked out too well so it seems that I need some help from you, the elite. Example: #!/bin/sh counter=0 until (($counter>5)) counter2=1 until (($counter2>6)); do if ;... (5 Replies)
Discussion started by: TehOne
5 Replies

6. Shell Programming and Scripting

awk issue expanding variables in ksh script

Hi Guys, I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need. I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles. ... (3 Replies)
Discussion started by: gazza-o
3 Replies

7. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies

8. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies

9. Shell Programming and Scripting

Possible ksh93 Bug Expanding Variables?

My OS is Linux (kernel 4.08.something) and AIX (7100-04-01-1543), the used ksh versions are: ksh88: Version M-11/16/88f (AIX) ksh93: Version M 93t+ 2009-05-01 (AIX), Version M 93u (Linux) When writing a parser for stanza files in ksh i encountered a rather strange behavior. Here is a... (4 Replies)
Discussion started by: bakunin
4 Replies

10. UNIX for Beginners Questions & Answers

Bash argument not expanding in script

I pass an argument to bash as run. The first command in green executes as expected, however the second in blue fails as the $run does not expand. I tried to escape the variable with \ thinking the quotes were making the literal translation and also "${run}" but both did not work to expand the... (3 Replies)
Discussion started by: cmccabe
3 Replies
GETOPTS(3)						  libbash getopts Library Manual						GETOPTS(3)

NAME
getopts -- libbash library for command line parameters parsing SYNOPSIS
$retval getopt_long <Instructions> <Parameters> DESCRIPTION
This is a documentation for libbash getopts library, that implements getopt_long function for bash(1). For documentation of bash getopts function, please see getopts(1) ( getopts(1posix) on some systems). Here is a table for reference: getopts(1) (or 1posix on some systems) implemented by bash getopts(3) implemented by libbash. getopt(1) implemented by getopt utils (part of util-linux) getopt_long(1) implemented by libbash and installed to section 1 instead of 3 to prevent collision with C man pages. getopt(3) implemented by GNU C library. getopt_long(3) implemented by GNU C library. I have also seen separate getopt utility which part of util-linux package. The getopt_long function parses the command line arguments. It uses Instructions as the rules for parsing the Parameters. The Instructions A string that specifies rules for parameters parsing. The instructions string is built of a group of independent instructions, separated by a white space. Each instruction must have the following structure: -<SingleLetter>|--<MultiLetter>-><VariableName>[:] This structure contains three parts: -<SingleLetter> This is the parameter single-letter sign. For example -h. --<MultiLetter> This is the parameter's corresponding multi-letter sign. For example --help. <VariableName>[:] This is the name of the variable that will contain the parameter value. For example: HELP. The Variable name can represent one of two variables types: Flag variable (not followed by ':') In this case, it will hold the value 1 if 'on' (i.e. was specified on command line) and will not be defined if 'off'. Value variable (followed by ':') In this case, the value it will hold is the string that was given as the next parameter in the Parameters string (Separated by white-space or '=' ). If input contains more then one instance of the considered command line option, an array of the given parameters will be set as the value of the variable. The Parameters The Parameters are simply the parameters you wish to parse. RETURN VALUE
This function returns a string that contains a set of variables definitions. In order to define the variables, this string should be given as a parameter to eval function. This value is returned in the variable $retval. EXAMPLES
Parse command line parameters looking for the flags -h | --help and -v | --version and for the value -p | --path : getopt_long '-h|--help->HELP -v|--version->VERSION -p|--path->PATH:' $* eval $retval In this example, for the parameters --help --path=/usr/ the variables that will be created are: HELP=1 PATH=/usr/ for the parameters --help --path=/usr --path=/bin the variables that will be created are: HELP=1 PATH=(/usr /bin) BUGS
Values must not contain the string `__getopts__'. This string will be parsed as a single white-space. A value should not start with an already defined multi-letter sign. If such a value exists, it will be treated as the equivalent singe-letter sign. This bug only accures when using a single-letter sign, or a multi-letter sign that are not followed by a `='. For example: If we have a script named `foo', and we parse the parameters `-d|--dir:' and `-f|--file:', then foo -d --file and foo --dir --file will not work foo --dir=--file will work. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), getopt_long(1), getopts(1), getopt(1), libbash(1), getopt(3), getopt_long(3) Linux Epoch Linux
All times are GMT -4. The time now is 02:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy