Sponsored Content
Top Forums Shell Programming and Scripting Bash - Nesting if statement in for loop Post 302879399 by Akshay Hegde on Thursday 12th of December 2013 09:22:50 AM
Old 12-12-2013
to compare integer do like this

if [ "$element" -eq "1" ]; then

for string if [ "$element" == "1"]; then

Code:
for element in 1 2; do 
if [ "$element" == "1" ]; then
      el="p"
else
      el="t"
fi
done

it's good to use double quotes while comparing

Last edited by Akshay Hegde; 12-12-2013 at 10:30 AM..
This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

if statement in for loop of a string

I am attempting to pass a string into awk and loop through it, and then for every occurrance of a certain character perform an action. In this case, for example, echo 1 for each time character r is found in the string. Except I can't get it to work. Could someone please tell me why? echo... (7 Replies)
Discussion started by: Sniper Pixie
7 Replies

2. UNIX for Dummies Questions & Answers

if statement in a while loop

#!/usr/bin/ksh echo Please enter while read n do echo $n >> datafile done question: How can I enject an if statement that if the users enter 0 (zero) the program will exit? this is what I have but not working #!/usr/bin/ksh echo Please enter number while read n do if $n=0 then... (2 Replies)
Discussion started by: bobo
2 Replies

3. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

4. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

5. Shell Programming and Scripting

BASH Varible nesting and user input

Well, I think I've managed to take two different issues and conglomerate them into and embarrasing mess. #!/bin/bash # Set some variables dir1=/path/that/isnt/variable/$variabledir/dir/ dir2=/path/that/isnt/variable/$variabledir/important/"$variabledir"-subdirectory/path/ echo "Gimme... (7 Replies)
Discussion started by: karlp
7 Replies

6. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

7. Shell Programming and Scripting

Help With Loop in Case Statement script

I am writing a bash script that asks the user for input and I need it to repeat until the user selects quit.. I dont know how to write the loop for it I searched all over but i still do not get it.. if anyone could help with this it would be greatly apprciated here is my script so far: #!... (2 Replies)
Discussion started by: Emin_Em
2 Replies

8. Shell Programming and Scripting

how to create a loop in an if statement

Hey guys, a=`cat abc | wc -l` b=`cat def | wc -l` if $a== $b then echo "a" else echo "b" fi I want the if condition to retry itself , untill a==b. I can't use goto statemt. Please help. Thanx in advance. Please use next time code tags for your code and data (5 Replies)
Discussion started by: jaituteja
5 Replies

9. Shell Programming and Scripting

awk if statement in a for loop?

I need to match multiple values in a single column in a file: example: Source file: abd,123,one def,232,two ghi,987,six Target file: 12345,abcde,123 09876,zxvyr,566 56789,lmnop,232 Variable: var1=`grep 2 sourcefile | awk '{print$1}' essentially, echo "$var1" would read:... (2 Replies)
Discussion started by: kopfgeldjagar
2 Replies

10. Shell Programming and Scripting

While loop within if statement

Hi, I'm a rookie who is trying to learn this stuff. What I need help with is putting together a non complicated "while" loop within the below "if" statement. I also need the while loop to keep looping until the user types a key to end the loop. Please reveal the proper insertion points. Thank... (4 Replies)
Discussion started by: jefferj54
4 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a file name containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 02:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy