Sponsored Content
Top Forums Shell Programming and Scripting S# in a for loop - concatenate $(loop counter) Post 302536580 by agama on Tuesday 5th of July 2011 11:36:53 PM
Old 07-06-2011
Quote:
Originally Posted by Aia
Code:
else
	shift
	
	for arg in $@
	do	
		if [ -f "$arg" ]
		then
			echo "$arg exists"
		fi
	done	
fi

I'd make one small change to Aia's suggestion:

Code:
for arg in "$@"

Quoting $@ preserves any whitespace that might have been a part of the parameter on the command line. Unfortunately people do create filenames which have spaces, and if the command line were something like this

Code:
script-name nosuchfile "my big file"

using $@ without the quotes would cause the loop to execute and test "my" "big" and "file" as three separate names, rather than the single name entered on the command line.

Filenames with spaces are a personal pet peeve, and your environment might not have any for you to worry about, but from a more generic command line processing perspective, knowing the difference between $@ and "$@" might make a difference as you write scripts in future.
This User Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Loop counter variable display

Hello everyone, how can I send output to the screen from a running script or tcl, in such a way that if a loop is executing I will see the rolling counter on my screen as the records are processed in the loop. I do not want the screen to scroll, though. In other words can a var's value be painted... (2 Replies)
Discussion started by: lifespan
2 Replies

2. Shell Programming and Scripting

Using the counter of a for loop in command line parameter

Say I have (in psuedocode) For i=1 to 10 tar cvfb /... 5*i /junk(i) end What I mean is that I want each successive for loop to have the block size parameter be 5 times the current counter. This isn't my actual code, just a stupid example...So the question is how do I descrive that parameter... (2 Replies)
Discussion started by: jeriryan87
2 Replies

3. Shell Programming and Scripting

adding counter to a variable while moving in a loop

The scenario is like this : I need to read records from a file one by one and increment counter1, if a certain field matches with a number say "40"..the script should increment the counter2 and also extract a corresponding field from the same line and adding them one by one and redirecting the the... (5 Replies)
Discussion started by: mady135
5 Replies

4. Shell Programming and Scripting

loop with a counter on a constant in bash

Hello Everyone, I'm in need of assistance on creating a script with a counter on a certain string. Basically this script opens a log file and displays certain log data. There are two key words in the log. START and FINISH. In between the START and FINISH is a variable ACTNUMBER. It will... (1 Reply)
Discussion started by: rxc23816
1 Replies

5. Shell Programming and Scripting

File merging based on different counter loop

hello, File 1 main Group sub group MIT VAR_1D_DATA_TYPE 23-03-2012 MIT VAR_1D_DATA_TYPE 22-03-2012 MIT VAR_10D_DATA_TYPE 23-03-2012 MIT VAR_10D_DATA_TYPE 22-03-2012 MIT ... (0 Replies)
Discussion started by: manas_ranjan
0 Replies

6. Shell Programming and Scripting

How to implement the counter in loop?

Hi, I am working on a script where I need to add one functionality i.e. to could the number of tar files at particular location...but the script is working in below way. 1) create sandbox 2) Drop old member function 3) addmember function 4) Apply checkpoint lable 5) Resync operation(This... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

7. Shell Programming and Scripting

Loop usage with counter

Hi friends, I just want to try some thing with shell using loop and counter I have 30 Directory, in each directory number of files say 5, 10, 20 etc... directory_1 directory_2 directory_n what I want to do is read files from directory_1 say 5 files if my counter is like this m=2000 ... (6 Replies)
Discussion started by: Akshay Hegde
6 Replies

8. Shell Programming and Scripting

Avoid multiple emails being sent - Counter, Loop?

Hello, I have currently coded a bash script below in which it does the following: # Archives compressed file from another location. Basically it moves *.gz files to another location. The script also sends an email whenever a new compressed file is placed. This is the issue that i... (5 Replies)
Discussion started by: Wizard_1979
5 Replies

9. Shell Programming and Scripting

Loop counter resets by itself

Hi! Can anyone explain this? The counter CDR_count should go on forever, but it suddenly resets at every step of the FOR loop (I know this because $_file has exactly 378 records). However, the counter reset is OUTSIDE the FOR loop. What's going on?? #!/bin/bash if || ; then echo ... (8 Replies)
Discussion started by: Flavius
8 Replies

10. Shell Programming and Scripting

While loop with limit counter

#!/usr/bin/ksh c=0 while ]; do echo /tmp/unex NOT found, iter : $c; ((c = $c + 1)); sleep 2; done so, the above counter doesn't work, already tried both -lt & -gt, and changed || to && so what am I missing? Thanks in advance (5 Replies)
Discussion started by: unexistance
5 Replies
DSA_generate_parameters(3openssl)				      OpenSSL					 DSA_generate_parameters(3openssl)

NAME
DSA_generate_parameters - generate DSA parameters SYNOPSIS
#include <openssl/dsa.h> DSA *DSA_generate_parameters(int bits, unsigned char *seed, int seed_len, int *counter_ret, unsigned long *h_ret, void (*callback)(int, int, void *), void *cb_arg); DESCRIPTION
DSA_generate_parameters() generates primes p and q and a generator g for use in the DSA. bits is the length of the prime to be generated; the DSS allows a maximum of 1024 bits. If seed is NULL or seed_len < 20, the primes will be generated at random. Otherwise, the seed is used to generate them. If the given seed does not yield a prime q, a new random seed is chosen and placed at seed. DSA_generate_parameters() places the iteration count in *counter_ret and a counter used for finding a generator in *h_ret, unless these are NULL. A callback function may be used to provide feedback about the progress of the key generation. If callback is not NULL, it will be called as follows: o When a candidate for q is generated, callback(0, m++, cb_arg) is called (m is 0 for the first candidate). o When a candidate for q has passed a test by trial division, callback(1, -1, cb_arg) is called. While a candidate for q is tested by Miller-Rabin primality tests, callback(1, i, cb_arg) is called in the outer loop (once for each witness that confirms that the candi- date may be prime); i is the loop counter (starting at 0). o When a prime q has been found, callback(2, 0, cb_arg) and callback(3, 0, cb_arg) are called. o Before a candidate for p (other than the first) is generated and tested, callback(0, counter, cb_arg) is called. o When a candidate for p has passed the test by trial division, callback(1, -1, cb_arg) is called. While it is tested by the Miller- Rabin primality test, callback(1, i, cb_arg) is called in the outer loop (once for each witness that confirms that the candidate may be prime). i is the loop counter (starting at 0). o When p has been found, callback(2, 1, cb_arg) is called. o When the generator has been found, callback(3, 1, cb_arg) is called. RETURN VALUE
DSA_generate_parameters() returns a pointer to the DSA structure, or NULL if the parameter generation fails. The error codes can be obtained by ERR_get_error(3). BUGS
Seed lengths > 20 are not supported. SEE ALSO
dsa(3), ERR_get_error(3), rand(3), DSA_free(3) HISTORY
DSA_generate_parameters() appeared in SSLeay 0.8. The cb_arg argument was added in SSLeay 0.9.0. In versions up to OpenSSL 0.9.4, call- back(1, ...) was called in the inner loop of the Miller-Rabin test whenever it reached the squaring step (the parameters to callback did not reveal how many witnesses had been tested); since OpenSSL 0.9.5, callback(1, ...) is called as in BN_is_prime(3), i.e. once for each witness. =cut OpenSSL-0.9.8 Oct 11 2005 DSA_generate_parameters(3openssl)
All times are GMT -4. The time now is 05:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy