Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Picking script options in bash Post 303044271 by Danette on Monday 17th of February 2020 07:06:05 PM
Old 02-17-2020
I want to check if the option is set so I can then assign the variable flnm.

But I do not know how I can do it. I expected the -z expressions to work.
--- Post updated at 12:31 AM ---

I have also tried the using -v and removed all the code after the if statement. Still same problem.

Code:
if [[ -v arg_Smirs ]]; then
  flnm="${txPath}/${flnm01a}"
elif if [[ -v arg_Capav ]]; then
  flnm="${txPath}/${flnm02a}"
elif if [[ -v arg_Igmfn ]]; then
  flnm="${txPath}/${flnm03a}"
elif if [[ -v arg_Segpi ]]; then
  flnm="${txPath}/${flnm04a}"
elif if [[ -v arg_Exads ]]; then
  flnm="${txPath}/${flnm05a}"
elif if [[ -v arg_Isemi ]]; then
  flnm="${txPath}/${flnm06a}"
elif if [[ -v arg_Cocpl ]]; then
  flnm="${txPath}/${flnm07a}"
elif [[ -v arg_file ]]; then
  flnm="${txPath}/${arg_file}"
else
  flnm="${txPath}/${flnm04a}"
fi

--- Post updated at 12:56 AM ---

Solved.
Code:
elif if

Could not see it for some reason !!!
--- pdated at 01:06 AM ---

I am using [ -v arg ]; and I am wondering whether I would be better off with [[ -v arg ]];

Perhaps not, as I do not need globbing for checking existence of variables

Code:
if [ -v arg_Smirs ]; then
  flnm="${txPath}/${flnm01a}"


Last edited by Danette; 02-17-2020 at 08:42 PM..
This User Gave Thanks to Danette For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing options to a bash script

I'm just not sure where to start looking into this. I want to be able to create switches for my script. Back in the day I'd make my scripts interactive...you know: echo "what report do you want" echo "A)boxes with errors" echo "B)boxes with more than 5 errors" echo "C)Service groups that have... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

2. Shell Programming and Scripting

Picking high and low variables in a bash script - possible?

Is it possible to have a bash script pick the highest and lowest values of four variables? I've been googling for this but haven't come up with anything. I have a script that assigns variables ($c0, $c1, $c2, and $c3) based on the coretemps from grep/sed statements of sensors. I'd like to also... (5 Replies)
Discussion started by: graysky
5 Replies

3. Shell Programming and Scripting

bash script to compile multiple .c files with some options

I'm trying to write a bash script and call it "compile" such that running it allows me to compile multiple files with the options "-help," "-backup," and "-clean". I've got the code for the options written, i just can't figure out how to read the input string and then translate that into option... (5 Replies)
Discussion started by: travis.batzer
5 Replies

4. Homework & Coursework Questions

how to create new options of "dd command" using bash script?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Creating bash script the dd command and its new options (-l -U) -l options to lowercase contents of file -U... (2 Replies)
Discussion started by: katherineskye1
2 Replies

5. UNIX for Advanced & Expert Users

how to add new options in bash script

what i want to be is that i would like to reinvent new options that have the same functionality as ... -u is the same functionality of conv=ucase and -l have the same functionality as conv=lcase... is there a way that i can put these in my script so that whenever i will typed in command... (12 Replies)
Discussion started by: aphryllyn1
12 Replies

6. Shell Programming and Scripting

Reading command line options from bash script

I have the following code and I am calling it using ./raytrac.bash -u and getting problems. For some reason opt_usage is still 0. opt_usage=0 iarg=0 narg=$# while (($iarg < $narg)) do (( iarg = $iarg + 1 )) arg=$argv usrInputFlag=`echo $arg | awk '/=/ {print 1}; ! /=/... (22 Replies)
Discussion started by: kristinu
22 Replies

7. Shell Programming and Scripting

Bash shell script not working-picking segment patterns from a file

Hi All, I have to pick particular segments from a file and I have prepared below shell script.But its not working and I am not able to find out whats the issue.could you guys pls help? Sample file: TS3*1451575*12*20151231*4*482.44 NM1*QC*1*CUTLER*BETTY DTM*472*20150808... (4 Replies)
Discussion started by: Venkata Prasad
4 Replies

8. Shell Programming and Scripting

Running options in bash script

Hello UNIX & Linux Forums community! Long time Linux daily user hobbyist, new to shell scripting.... I'm working on a script that does all the "work" in one script, and makes calls to a second script to display info to the user via mostly expanding variables in heredocs. I'm contemplating... (6 Replies)
Discussion started by: Cody Learner
6 Replies

9. Shell Programming and Scripting

Bash: Picking up filenames then moving to next directory

I have a collection of directories, for example as below I want to create a loop that goes in the first directory and picks up the *hhz*.sac.pzs filename in a variable, and the other files matching *hhz*.sac in another variable (however I do not want to pick the *hhz*.sac.pzs). This is because... (4 Replies)
Discussion started by: kristinu
4 Replies
UNIFDEF(1)						    BSD General Commands Manual 						UNIFDEF(1)

NAME
unifdef, unifdefall -- remove preprocessor conditionals from code SYNOPSIS
unifdef [-ceklst] [-Ipath] [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [-o output] [file] unifdefall [-Ipath] ... file DESCRIPTION
The unifdef utility selectively processes conditional cpp(1) directives. It removes from a file both the directives and any additional text that they specify should be removed, while otherwise leaving the file alone. The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines, and it understands only the commonly-used subset of the expression syntax for #if and #elif lines. It handles integer values of symbols defined on the command line, the defined() operator applied to symbols defined or undefined on the command line, the operators !, <, >, <=, >=, ==, !=, &&, ||, and parenthesized expressions. Anything that it does not understand is passed through unharmed. It only processes #ifdef and #ifndef directives if the symbol is specified on the command line, otherwise they are also passed through unchanged. By default, it ignores #if and #elif lines with constant expressions, or they may be processed by specifying the -k flag on the command line. The unifdef utility also understands just enough about C to know when one of the directives is inactive because it is inside a comment, or affected by a backslash-continued line. It spots unusually-formatted preprocessor directives and knows when the layout is too odd to handle. A script called unifdefall can be used to remove all conditional cpp(1) directives from a file. It uses unifdef -s and cpp -dM to get lists of all the controlling symbols and their definitions (or lack thereof), then invokes unifdef with appropriate arguments to process the file. Available options: -Dsym[=val] Specify that a symbol is defined, and optionally specify what value to give it for the purpose of handling #if and #elif directives. -Usym Specify that a symbol is undefined. If the same symbol appears in more than one argument, the last occurrence dominates. -c If the -c flag is specified, then the operation of unifdef is complemented, i.e., the lines that would have been removed or blanked are retained and vice versa. -e Because unifdef processes its input one line at a time, it cannot remove preprocessor directives that span more than one line. The most common example of this is a directive with a multi-line comment hanging off its right hand end. By default, if unifdef has to process such a directive, it will complain that the line is too obfuscated. The -e option changes the behaviour so that, where pos- sible, such lines are left unprocessed instead of reporting an error. -k Process #if and #elif lines with constant expressions. By default, sections controlled by such lines are passed through unchanged because they typically start ``#if 0'' and are used as a kind of comment to sketch out future or past development. It would be rude to strip them out, just as it would be for normal comments. -l Replace removed lines with blank lines instead of deleting them. -o output The argument given is the name of an output file to be used instead of the standard output. This file can be the same as the input file. -s Instead of processing the input file as usual, this option causes unifdef to produce a list of symbols that appear in expressions that unifdef understands. It is useful in conjunction with the -dM option of cpp(1) for creating unifdef command lines. -t Disables parsing for C comments and line continuations, which is useful for plain text. -iDsym[=val] -iUsym Ignore #ifdefs. If your C code uses #ifdefs to delimit non-C lines, such as comments or code which is under construction, then you must tell unifdef which symbols are used for that purpose so that it will not try to parse comments and line continuations inside those #ifdefs. One specifies ignored symbols with -iDsym[=val] and -iUsym similar to -Dsym[=val] and -Usym above. -Ipath Specifies to unifdefall an additional place to look for #include files. This option is ignored by unifdef for compatibility with cpp(1) and to simplify the implementation of unifdefall. The unifdef utility copies its output to stdout and will take its input from stdin if no file argument is given. The unifdef utility works nicely with the -Dsym option of diff(1). DIAGNOSTICS
Too many levels of nesting. Inappropriate #elif, #else or #endif. Obfuscated preprocessor control line. Premature EOF (with the line number of the most recent unterminated #if). EOF in comment. The unifdef utility exits 0 if the output is an exact copy of the input, 1 if not, and 2 if in trouble. SEE ALSO
cpp(1), diff(1) HISTORY
The unifdef command appeared in 4.3BSD. ANSI C support was added in FreeBSD 4.7. BUGS
Expression evaluation is very limited. Preprocessor control lines split across more than one physical line (because of comments or backslash-newline) cannot be handled in every situation. Trigraphs are not recognized. There is no support for symbols with different definitions at different points in the source file. The text-mode and ignore functionality does not correspond to modern cpp(1) behaviour. BSD
June 5, 2009 BSD
All times are GMT -4. The time now is 04:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy