Sponsored Content
Full Discussion: if condition in a while loop
Top Forums Shell Programming and Scripting if condition in a while loop Post 302471379 by svajhala on Friday 12th of November 2010 03:37:25 PM
Old 11-12-2010
if condition in a while loop

Gurus,

I need to read a line from a file and strip the characters from it and compare the stripped value with the value I pass to the script while executing it. Below is the code for the same. But when i execute the code, it is throwing an error.

Code:
#!/bin/ksh

. /home/.i_env

FOLDER_NAME=$1
APP=$2


while read line

   grp=${line%_*}

if [ $APP -eq $grp ]; then

   group=${line%,*}
   perm=${line#*,}

# "doing something here using above variables"   
fi
done < i_groups.txt

Below is the data from i_groups.txt

Code:
ADM_GRP,RWX
CTF_DEVS,RWX
CTF_ADM,RWX
CTF_TESTERS,RX
MTF_DEVS,RWX
MTF_ADM,RWX
MTF_TESTERS,RX
LTF_DEVS,RWX
 LTF_ADM,RWX
 LTF_TESTERS,RX

When I execute the script, it is giving the below error:
Code:
test2.ksh[20]: syntax error at line 46 : `done' unexpected

Please shed some light on this.

-Sam
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What condition to be put in the while loop?

i have got a file where the env command is appended 5 times. i have to now look for the username and display it in the form of 1) PWD=/home/lee.ballancore 2) USER=lee.ballancore 3) MAIL=/var/spool/mail/lee.ballancore 4) LOGNAME=lee.ballancore 5) HOME=/home/lee.ballancore 6)... (1 Reply)
Discussion started by: nehaquick
1 Replies

2. UNIX for Dummies Questions & Answers

Testing For Loop condition

How do I test the return condition in the script if no files are found: for file in `Find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN}` do ... .. done I want to capture the return code so I can echo the error or condition. Using if ] always returns zero no matter where it's placed. ... (4 Replies)
Discussion started by: mavsman
4 Replies

3. Shell Programming and Scripting

how can i put the condition in for loop for the below.

i have the equation like below 07:35:07 ( AB : 2319f.ab * 22) + ( AB : 2320f.ab * 22.03 ) + ( AB :2321f.ab * 22.07 ) ...... N i want put ":" as a delimiter and break the equation like below 2319f.ab * 22 2320f.ab *22.03 2321f.ab * 22.07 . . N i know the number of... (1 Reply)
Discussion started by: mail2sant
1 Replies

4. Shell Programming and Scripting

issues with a condition in a while loop

Hi, I am facing issues with test condition. I had a compound condition to write for both if and while, In one of the texts i referred, with a korn shell we can write compound statements like: ], however this doesn't worked for me. For example: if ] doesn't works, but if || worked. ... (1 Reply)
Discussion started by: amritps
1 Replies

5. Shell Programming and Scripting

Use of -z in while loop condition

Hi, Could you please tell what is the meaning of -z in while loop condition. For example, while ; do echo "*** Enter the age " readage (3 Replies)
Discussion started by: vidyaj
3 Replies

6. Shell Programming and Scripting

Leaving for loop on condition

hi all, i have a problem...no dream :-) i want to scan a file i use the loop famous while read line do do < myfile but this scan must finish when find the another string . How can i do it? best regards for all. Francesco Please use descriptive subjects. "script." doesn't tell... (5 Replies)
Discussion started by: FrancescoIt
5 Replies

7. Shell Programming and Scripting

Case loop condition

hello, I would like to do exit at the end ie list all errors before exiting How to put the token exit in a variable with a loop ? Thanks function g1 () { case "$1" in (-0-0 | -0-1 | -0-2 | -0-3 | -1-0 | -1-1 | -1-2 | -1-3) # nothing, OK ! ;; (*) echo 'Fatal, $1 = '"'$1'"', Date... (9 Replies)
Discussion started by: amazigh42
9 Replies

8. Shell Programming and Scripting

While Loop with if else condition

Hi, I was trying to write a shell script which reads csv file and sends mail in html format along with tables. Hope i have completed 1st part , but while sending mail i was trying to highlight some rows in the table based on the egrep outcome. If the string exists in line/INPUT, i am trying to... (4 Replies)
Discussion started by: varmas424
4 Replies

9. Shell Programming and Scripting

Check two condition in while loop

Hi, I Have to check two condition in while loop every 2 minutes. while loop is accompanied with number of times it will check.Please help in putting the two condition in while loop as appropriate. z= input value, A=1 while do 1.check the file output,if the file output is N then keep on... (2 Replies)
Discussion started by: netdbaind
2 Replies

10. Shell Programming and Scripting

For loop/while condition - doubt

hi., As we know that using for-loop or while condition, we can only process one by one sequentially, but , lets say this example : 1. under the folder "logs" there are 1000 files 2. each file has one record or line 3. have to perform atleast 7 queries per 3 seconds ,for instance ... (3 Replies)
Discussion started by: alnhk
3 Replies
CHMOD(2)						      BSD System Calls Manual							  CHMOD(2)

NAME
chmod, fchmod -- change mode of file SYNOPSIS
#include <sys/types.h> #include <sys/stat.h> int chmod(const char *path, mode_t mode); int fchmod(int fildes, mode_t mode); DESCRIPTION
The function chmod() sets the file permission bits of the file specified by the pathname path to mode. Fchmod() sets the permission bits of the specified file descriptor fildes. Chmod() verifies that the process owner (user) either owns the file specified by path (or fildes), or is the super-user. A mode is created from or'd permission bit masks defined in <sys/stat.h>: #define S_IRWXU 0000700 /* RWX mask for owner */ #define S_IRUSR 0000400 /* R for owner */ #define S_IWUSR 0000200 /* W for owner */ #define S_IXUSR 0000100 /* X for owner */ #define S_IRWXG 0000070 /* RWX mask for group */ #define S_IRGRP 0000040 /* R for group */ #define S_IWGRP 0000020 /* W for group */ #define S_IXGRP 0000010 /* X for group */ #define S_IRWXO 0000007 /* RWX mask for other */ #define S_IROTH 0000004 /* R for other */ #define S_IWOTH 0000002 /* W for other */ #define S_IXOTH 0000001 /* X for other */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ #define S_ISVTX 0001000 /* save swapped text even after use */ The ISVTX (the sticky bit) indicates to the system which executable files are shareable (the default) and the system maintains the program text of the files in the swap area. The sticky bit may only be set by the super user on shareable executable files. If mode ISVTX (the `sticky bit') is set on a directory, an unprivileged user may not delete or rename files of other users in that directory. The sticky bit may be set by any user on a directory which the user owns or has appropriate permissions. For more details of the properties of the sticky bit, see sticky(8). Writing or changing the owner of a file turns off the set-user-id and set-group-id bits unless the user is the super-user. This makes the system somewhat more secure by protecting set-user-id (set-group-id) files from remaining set-user-id (set-group-id) if they are modified, at the expense of a degree of compatibility. RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
The chmod() system call will fail and the file mode will be unchanged if: [EACCES] Search permission is denied for a component of the path prefix. [EFAULT] Path points outside the process's allocated address space. [EINTR] Its execution was interrupted by a signal. [EIO] An I/O error occurred while reading from or writing to the file system. [ELOOP] Too many symbolic links were encountered in translating the pathname. This is taken to be indicative of a looping sym- bolic link. [ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters. [ENOENT] The named file does not exist. [ENOTDIR] A component of the path prefix is not a directory. [EPERM] The effective user ID does not match the owner of the file and the effective user ID is not the super-user. [EROFS] The named file resides on a read-only file system. fchmod() will fail if: [EBADF] fildes is not a valid file descriptor. [EINVAL] fildes refers to a socket, not to a file. [EINVAL] mode is not a valid file mode. [EINTR] Its execution was interrupted by a signal. [EIO] An I/O error occurred while reading from or writing to the file system. [EPERM] The effective user ID does not match the owner of the file and the effective user ID is not the super-user. [EROFS] The file resides on a read-only file system. LEGACY SYNOPSIS
#include <sys/types.h> #include <sys/stat.h> The include file <sys/types.h> is necessary. SEE ALSO
chmod(1), chown(2), open(2), stat(2), compat(5), sticky(8) STANDARDS
The chmod() function is expected to conform to IEEE Std 1003.1-1988 (``POSIX.1''). HISTORY
The fchmod() function call appeared in 4.2BSD. 4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution
All times are GMT -4. The time now is 05:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy