end of line error | Unix Linux Forums | Homework & Coursework Questions

  Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

end of line error

Homework & Coursework Questions


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-28-2012
swimmerbhs swimmerbhs is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 17 September 2013, 10:43 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
end of line error

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:



Code:
#/bin/sh -xv
#Author: Lauren Buecker
#Date: September 28 2012
#Class COP3353
#Assignment: Assignment 4
echo "There are "$#" pamaters"
if ($# ! = 1) then
echo " Error No Paramaters Passed"
exit
endif

2. Relevant commands, code, scripts, algorithms:

if statement

3. The attempts at a solution (include all code and scripts):

When I delete the if statement it works fine

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Florida State University, Tallahassee Fl USA David Gaitros COP3353

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Sponsored Links
    #2  
Old 09-28-2012
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 October 2014, 12:46 PM EDT
Location: Saskatchewan
Posts: 19,684
Thanks: 824
Thanked 3,352 Times in 3,139 Posts
This looks sort of like a csh script, but if/then in sh doesn't work quite that way. It uses -eq, -ne, and so forth to compare numbers. =, != are used to compare strings.

There must be spaces between the brackets and whatever is inside -- and outside -- them. sh uses single square brackets, or double square brackets, not single round brackets.

You have to put a then after if.

You end the if-statement with fi, not endif.

You probably want less-than, rather than equal or not-equal, since it's possible for there to be one or more arguments, not just one. less-than is abbreviated into -lt .


Code:
if [ "$#" -lt 1 ]
then
        echo " Error No Parameters Passed"
        exit
fi

See Test Operators for what else you can do inside [ ] .
Sponsored Links
    #3  
Old 09-28-2012
swimmerbhs swimmerbhs is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 17 September 2013, 10:43 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
So if i got that straight the first one i wrote was something that csh would be able to run?

The assignment does no say it has to be sh or csh but I have to ask for and the parameter, check to see if that is a directory and then see how many directories their are, files with read permission, files with write permission and files with execute permissions are.

when I try and put the other if statement to see if it was a directory it says to many arguments

if [ "$#" ! -d]

Code:
if [ "$#" ! -d]

also I did this

Code:
if [ $#" -d == "public_html" ]

same error

Last edited by swimmerbhs; 09-28-2012 at 02:49 PM..
    #4  
Old 09-28-2012
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 October 2014, 12:46 PM EDT
Location: Saskatchewan
Posts: 19,684
Thanks: 824
Thanked 3,352 Times in 3,139 Posts
Quote:
Originally Posted by swimmerbhs View Post
So if i got that straight the first one i wrote was something that csh would be able to run?
I'm not very proficient with c-shell. It looks like something from csh, though.

If you're not sure whether you're supposed to be learning csh or sh, you better find out fast, since they're nothing alike. Hopefully sh, since csh is to be avoided.

Quote:
The assignment does no say it has to be sh or csh but I have to ask for and the parameter, check to see if that is a directory and then see how many directories their are, files with read permission, files with write permission and files with execute permissions are.
I would always reccomend sh over csh.

Quote:
When I try and put the other if statement to see if it was a directory it says to many arguments
You made a syntax error there: -d] should be -d ] because as explained above, the brackets must have spaces between them and everything else.

I'm not sure why you're using $# there or what you're expecting it to do; $# is a special variable which means 'the number of arguments'. If you want the first argument, that's $1. $2 is the second, etc.


Code:
if [ -d "$1" ]
then
        echo "$1 is a folder"
fi

Note the double-quotes around $1. This will prevent $1 from splitting into multiple strings if it happens to have a space in it.
Sponsored Links
    #5  
Old 09-28-2012
swimmerbhs swimmerbhs is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 17 September 2013, 10:43 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I fixed the second if statement to read

Code:
if [ ! -d  "$1" ] 
then
        echo "Not a directory"
        exit
fi

but all directories parameters say it is not a directory.

after i save the file and input in to the command line
sh assignment4.sh public_html or sh assignment4.sh COP3353-temp which are all directories

Code:
buecker@shell:~/COP3353-temp>sh assignment4.sh public_html
Not a directory
buecker@shell:~/COP3353-temp>sh assignment4.sh COP3353-temp
Not a directory

---------- Post updated at 02:59 PM ---------- Previous update was at 02:55 PM ----------

ok i fixed the one one problem with passing in the paramater for the folder i was already in. but not the home directory

---------- Post updated at 03:12 PM ---------- Previous update was at 02:59 PM ----------


Code:
cd $1
set numdir = 0
set files = 0
set readfiles = 0
set writefiles = 0
set executefiles = 0
foreach  files [ * ]
echo "$files"   
end

for was a command not found, foreach is a command not found the instructor is showing us how to do it in a shell we are not supposed to use.

Code:
assignment4.sh: line 23: foreach: command not found

assignment4.sh: line 25: end: command not found
buecker@shell:~>

Sponsored Links
    #6  
Old 10-04-2012
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 October 2014, 12:46 PM EDT
Location: Saskatchewan
Posts: 19,684
Thanks: 824
Thanked 3,352 Times in 3,139 Posts
Sorry for missing this thread.

foreach is not a shell statement, you'd just use for.


Code:
for X in *
do
        echo "file is $X"
done

Sponsored Links
    #7  
Old 10-05-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 24 October 2014, 4:42 PM EDT
Location: Switzerland - GE
Posts: 5,835
Thanks: 162
Thanked 415 Times in 390 Posts
(foreach is definitely cshell syntax and only cshell or assimilated... (hehe poor guy...))
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to grep the line with error where keyword in next line is known. manishdivs Shell Programming and Scripting 4 09-16-2011 10:21 AM
Line too long error Replace string with new line line character ducati Solaris 4 05-17-2011 06:54 AM
Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected. amitsinha Shell Programming and Scripting 3 05-25-2010 02:44 AM
ERROR: ./launch_full_backup.sh[18]: Syntax error at line 28 : `else' is not expected. villenan Shell Programming and Scripting 2 08-30-2009 06:36 AM
I got error like...syntax error on line 1, teletype koti_rama UNIX for Advanced & Expert Users 2 07-07-2007 07:35 PM



All times are GMT -4. The time now is 12:46 PM.