Sponsored Content
Full Discussion: Variable on If Statement
Top Forums Shell Programming and Scripting Variable on If Statement Post 302746811 by Scott on Thursday 20th of December 2012 04:09:39 AM
Old 12-20-2012
It is called "parameter expansion".

An extract from the Korn shell man page:

Quote:
${parameter:-word}
If parameter is set and is non-null then substitute its value; otherwise substitute word.
Although your code seems to be missing the closing }.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using variable in case statement

I want to do this: Ex 1: case $answer in 1|2|3|4|5) echo $answer;; x) break;; *) echo "Invalid selection. Try again.";; esac But I need the part "1|2|3|4|5" to be fetched from a variable, like so: Ex 2: case $answer in $cases) echo $answer;; x) break;; *) echo "Invalid... (2 Replies)
Discussion started by: fialia
2 Replies

2. Shell Programming and Scripting

Can't interpret variable in if statement

Can someone help me out here. I can't get this piece of code to work. i.e. $ALL_EVENTS does not get interpreted in the if brackets. The first part is the code, the second part is the execution of the code. Note: $ALL_EVENTS does equal 2, but there is no value once passed to the if statement. ... (4 Replies)
Discussion started by: jwholey
4 Replies

3. Shell Programming and Scripting

help with variable substitution in case statement

I have a script where I take input from user and see if it falls in list of valid entry. --------------- #!/bin/ksh VALID_ENTRIES="4|5|6" echo "enter your choice" read reply IFS="|" echo "valid entries are $VALID_ENTRIES" case "$REPLY" in Q|q ) IFS="$IFS_SAVE";return ;;... (5 Replies)
Discussion started by: bhav_shah82
5 Replies

4. Shell Programming and Scripting

If statement in awk with external variable

So I have a if statement inside an awk to check if $2 of a awk equals a specific IP but the test fails. So here is what I have. # !/bin/sh echo "Enter client ID" read ID echo "Enter month (01, 02, 03)" read month echo "Enter day (03, 15)" read day echo "Enter Year (07, 08)" read... (6 Replies)
Discussion started by: doublejz
6 Replies

5. Shell Programming and Scripting

Assigning Variable to AWK statement

Hi, The following command runs on in the Korn shell prompt. however i want to output the value of this to a variable. Can anyone provide a solution? echo 'ABC,DEF,"G,HI,J",KLM,"MNi,O"'| awk -F "\"" '{for(i=1;i<=NF;i++){if(i%2)gsub("\,","~^~",$i)}}1' (2 Replies)
Discussion started by: ladarlsan
2 Replies

6. Shell Programming and Scripting

Select variable within a if statement

i want to select a variable created and use it in a if statement, but not getting the desired results LINE='device for 0101a01: lpd://172.25.41.111:515' prt=`echo $LINE | awk '{print $3 }' | cut -c 1-7` echo $prt My if statement to select just what i want.. IFS=$":" while read prt... (11 Replies)
Discussion started by: ggoliath
11 Replies

7. Programming

Assign variable for INSERT INTO statement

Hello, Can anyone tell me that, How can I assign variable to shell script variable, which i need to use in INSERT INTO statement? my shell script variables are, EMPNAME=`regular expression` EMPID=`regular expression` EMPBDATE=`regular expression` Now through ksh script I am... (16 Replies)
Discussion started by: Poonamol
16 Replies

8. Shell Programming and Scripting

set variable using 'ls' with an 'or' conditional statement

Hi, I would like to set a variable using ls, but I need to be able to list two possibilities simultaneously, i.e., I'd like to do this all on one line. These are the two possible directories, but keep in mind only *one* will be present at any given time: drwxrwxrwx 4 qtv qtv 16384 Nov 9... (5 Replies)
Discussion started by: goodbenito
5 Replies

9. Shell Programming and Scripting

awk - updating variable in if statement

I have another question I am stuck at :wall: I have a text file with two columns, like so... 2 0.0627279 3 0.0794451 4 0.108705 5 0.137739 6 0.190394 7 0.217407 8 0.241764 9 0.344458 10 0.460762 I'd like to go through the file line by line until the value in the second column... (3 Replies)
Discussion started by: origamisven
3 Replies

10. Shell Programming and Scripting

Variable IF statement in awk

I have multiple requirements to run data extracts (with the same basic requriement / resulsts) however the parameters of the extracts change with each request. To help make life easier I am writing a script where the parameters for the specific request are set at the start and then used as needed.... (6 Replies)
Discussion started by: meike
6 Replies
PPI::Statement::Variable(3pm)				User Contributed Perl Documentation			     PPI::Statement::Variable(3pm)

NAME
PPI::Statement::Variable - Variable declaration statements SYNOPSIS
# All of the following are variable declarations my $foo = 1; my ($foo, $bar) = (1, 2); our $foo = 1; local $foo; local $foo = 1; LABEL: my $foo = 1; INHERITANCE
PPI::Statement::Variable isa PPI::Statement::Expression isa PPI::Statement isa PPI::Node isa PPI::Element DESCRIPTION
The main intent of the "PPI::Statement::Variable" class is to describe simple statements that explicitly declare new local or global variables. Note that this does not make it exclusively the only place where variables are defined, and later on you should expect that the "variables" method will migrate deeper down the tree to either PPI::Statement or PPI::Node to recognise this fact, but for now it stays here. METHODS
type The "type" method checks and returns the declaration type of the statement, which will be one of 'my', 'local', 'our', or 'state'. Returns a string of the type, or "undef" if the type cannot be detected (which is probably a bug). variables As for several other PDOM Element types that can declare variables, the "variables" method returns a list of the canonical forms of the variables defined by the statement. Returns a list of the canonical string forms of variables, or the null list if it is unable to find any variables. symbols Returns a list of the variables defined by the statement, as PPI::Token::Symbols. TO DO
- Write unit tests for this SUPPORT
See the support section in the main module. AUTHOR
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.10.1 2011-02-26 PPI::Statement::Variable(3pm)
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy