Spot the difference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Spot the difference
# 8  
Old 08-02-2006
ignore the line 27, its basically the end of the file (I added a little bit of code)
# 9  
Old 08-02-2006
Use code tags or I will sic the rapid pocket weasels on you!

They are simple. They are easy. In the editor they look like
[ code ]
stuff
[ / code ]

except without the spaces in the tags. They make it possible to read your code without spontaneous eyebleeding.
Code:
#!/bin/sh
case $# in
	0)	echo "Usage: enshar file [ ... ]" >&2
		exit 1
		;;
	*)	for file
		do	
		if [ -d $file ]
		then echo "enshar: $file is a directory" >&2
		exit 3
		elif [ ! -f $file ]
		then echo "enshar: $file doesn't exist" >&2
		exit 4
		elif [ ! -r $file ]
		then echo "enshar: $file can't be read" >&2
		exit 5 
		elif [ -h $file ]
		then echo "enshar: $file can't enshar" >&2 
		exit 6
		else 	
			echo "cat > $file <<\!EnShAr!\"
			echo "!EnShAr!"
			echo "set 'cksum $file'"
			echo"cksum" $file
			check=$1
			echo "test $1 = $check || echo $0: bad cksum in $file >&2 " >> shar
			echo "cat > $file <<\!EnShAr!" >> shar
		fi
		done
		;;
esac

# 10  
Old 08-02-2006
What's the "for file" thing meant to do? Usually you'd do something like

Code:
for Z in 'a' 'b' 'c' 'd' 'e'
do
        echo "${Z}"
done

but I see no values for your 'for'.
# 11  
Old 08-02-2006
it's supposed to be $file, thanks for that, and yes in future I will code my posts before you attack me with something pocket sized and unpleasent
# 12  
Old 08-02-2006
Does anyone else have any ideas why its not working, says theres a error at line 31 I think
# 13  
Old 08-02-2006
Repost.
Quote:
Originally Posted by Corona688
What's the "for file" thing meant to do? Usually you'd do something like

Code:
for Z in 'a' 'b' 'c' 'd' 'e'
do
        echo "${Z}"
done

but I see no values for your 'for'.
Note how the Z immediately after the 'for' doesn't have a $, and also notice how it's followed by the things you want Z to be. You don't appear to initialize file anywhere, either, and that one is not an automatic variable; neither do you list any values that file is supposed to loop through.

I also might suggest simplifying your code a bit... instead of making the whole thing one giant case statement, just check once at the beginning:

Code:
# Must have at least one commandline argument
if [[ $# -eq 0 ]]
then
        echo "Not enough arguments"
        exit 1
fi

# Continue on

Nested case/for/if/etc/ad/infinitums are nasty. Not nesting unless you've got a good reason to can spare you a lot of headaches.

Last edited by Corona688; 08-02-2006 at 08:01 PM..
# 14  
Old 08-03-2006
Okay, so I should give "file" a value by doing something like file=$1 yeah? where should I do that. Am I close to my objective here or way off? Sorry about this it's just taking me a min to get my head round it.

Are you saying I should put the file checking part in a if statement and then the shar part in another?

Is the case section of the script needed? can you see any reason why my script is not expecting a end of line section at the end? please help
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. AIX

Unable to create a SPOT

Hi everyone! Ok so I'm trying for the first time to install AIX on a LPAR with NIM. The NIM: root@oaexpnimp01(/home/root) # oslevel -s 6100-08-02-1316 I'm trying to install AIX 6.1 TL1. I successfully created a new lpp source root@oaexpnimp01(/home/root) # lsnim -l AIX61_TL1_2... (10 Replies)
Discussion started by: trivium012
10 Replies

2. UNIX for Dummies Questions & Answers

Can anyone help me to spot my mistake?

Hi there can anyone help me to spot my mistake and please explain why it appears My code : #!/usr/bin/gawk -f BEGIN { bytes =0} { temp=$(grep "datafeed\.php" | cut -d" " -f8) bytes += temp} END { printf "Number of bytes: %d\n", bytes } when I am running ./q411 an411 an411: ... (6 Replies)
Discussion started by: FUTURE_EINSTEIN
6 Replies

3. AIX

NIM SPOT query

Dear Admins, The SPOT defined in NIM is for aix 5.3 TL 7 . Some of the NIM clients are upgraded to TL 10 . Now the SPOT level is older than the mksysb level. This will cause problem during restoration of any NIM clients. Now i want to upgrade SPOT level to TL 10 and redefine the resources... (3 Replies)
Discussion started by: newaix
3 Replies

4. AIX

how to make a spot

HI. there My 10 servers are running on 6.1-05-03 aix including NIM server but my user want to update a TL (61-05-03 to 61-06-04) if I Update a AIx version of TL .. is that change the SPOT of NIM server.. OR if I make a spot of AIX7.1 and Is that support AIX 6.1 AIX 5.3 Images I... (1 Reply)
Discussion started by: Jeon Jun Seok
1 Replies

5. Shell Programming and Scripting

How do I search with regex in one spot?

Hello im new here and i shot stright with question. Mainly i wanna ask , how do i search with regexp in one spot and show the whole thing, what im trying to ask is , for eg. i do ls -l, and i see all the info for the dirs and dats. now say i wanna get all the dats that in their name they start... (2 Replies)
Discussion started by: Goroner
2 Replies

6. AIX

SPOT requirement

Hey May be a dumb question Can I use a SPOT which is at 5.3 TL6 to boot an LPAR (with 5.3 TL8) in to maintenance mode? Will it work ? Is it mandatory that SPOT should be of same or higher version in such case? Bala (1 Reply)
Discussion started by: balaji_prk
1 Replies

7. UNIX for Advanced & Expert Users

Spot

does somebody know about SPOT ?? any link about SPOT commands ? i ve made a mistake during configuration, :mad: then i ve started the system in Maintenance mode the only shell was SPOT. :eek: SPOT doesn t understand anything.... how do i work with SPOT ? thanks in advance Karine... :D (1 Reply)
Discussion started by: karine
1 Replies
Login or Register to Ask a Question