hi guys,
Unix dummy here.
I need help creating a script for class.
The assignment reads as follows:
create a script that will create a new schema in schema.txt, it must accept 7 arguments (the first being the name of the schema) the other 6 being the 6 field names. the schema has to be tested to make sure it isn't in the file schema.txt and if all passes then the arguments should be appended to the file schema.txt
this is what I have so far:
#!/bin/sh
if [ ! $# -ge 2 ] && [ ! $# -le 7 ]
then
echo "Usage: ns.sh <schema_name> <field_names>"
elif [ ! -f schemas.txt ]
echo "schemas.txt": file could not be found.
elif [ ! -r schemas.txt ]
echo "schemas.txt": unable to read file.
elif [ ! -w schemas.txt ]
echo "schemas.txt": unable to write upon file.
elif [ "`grep"^$1\" schema.txt`" ]
echo schema already defined as $1
else
$@ >> schema.txt
fi
when I run it, this happens:
sena@linprog1.cs.fsu.edu:~/a5>ns.sh cars make model year
ns.sh: line 7: syntax error near unexpected token `elif'
ns.sh: line 7: `elif [ ! -r schemas.txt ]'
As far as appending the arguments to schema I don't know what to do
Any help would be awesome!