[X-Unix] Re: Loop structure syntax question

Peter Dyballa Peter_Dyballa at Web.DE
Thu Nov 24 01:59:31 PST 2005


Am 24.11.2005 um 02:18 schrieb 
x-unix-request at listserver.themacintoshguy.com:

> foreach login ( `cat ./logins_A.txt` )
> dscl . merge /groups/cq users "$login"@<mydomain.com>
> end
>

"$login" looks a bit suspicious. ${login} cleanly separates the 
variable's name from other text.

'cat ./<some file>' is suspicious too. It completely relies on the fact 
that the shell script is run in the same directory where this file is. 
An absolute path name might be more appropriate, or a sequence of 
saving the current working directory, changing to that with the file, 
and returning.

Could be a better syntax is 'dscl . merge /groups/cq users 
"${login}@<mydomain.com>"'.

	( dscl . merge /groups/cq users "${login}@<mydomain.com>" ) >>& 
Errors_dscl.list
	printf "The command >%s< returned %d\n" "dscl . merge /groups/cq users 
${login}@<mydomain.com>" $status >> Errors_dscl.list

would log all errors in a file (Errors_dscl.list), which too would hold 
the actual dscl command and its return values. You can make the file's 
name an absolute path name.

--
Greetings

   Pete

Bake Pizza not war!



More information about the X-Unix mailing list