File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes i have finished making the scripts but.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "i have finished making the scripts but.." Watch "i have finished making the scripts but.." New topic
Author

i have finished making the scripts but..

johny doe
Ranch Hand

Joined: Dec 07, 2007
Posts: 78
but when i tried to run one of them i get
bad command error
regarding the first assigment
(1.Write a shell script program called valid that prints "yes" if the argument is a valid shell variable and "no" otherwise)

i wrote
=========
#!/bin/sh
if echo $1 | grep -q "[A-Za-z_][A-Za-z0-9_]*"
then
echo yes
else
echo no

=========
i saved the file as a.sh

i entered the directory in which the file is located and
wrote
a 123
i got a bad command
where i got it wrong

the second script :for the following assigment
Write a shell script program print_args that prints its arguments one per line and precedes each argument by its number.

i wrote:

#!/bin/sh
for i in $@; do
echo 1:$i
done

is it the coorect way??
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Since it looks like a school homework, you should probably test it yourself and see if you get the desired result. That way, you can learn more.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

The first script needs a 'fi' at the end - that way you close an if-statement.

Then it will start working, but it's not finished.

Grep will search inside $1 for a valid identifier.
123 no
aaa yes
a12 yes
1a1 yes <--- found: a1

You may use ^ (begin of expression) and $ (end of expression/line) to force the whole expression to match the pattern:
"^[A-Za-z_][A-Za-z0-9_]*$"

If the name of the script is a.sh, you have to call a.sh - not just a, because linux does not allow omitting the extension.
And if your current working directory is not in the path, you have to specify the path too:


./ is the current directory.

But probably your file is not executable.

Will CHange MODe for All users to be eXecutable.

To the second script: no. Try it.


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i have finished making the scripts but..
 
Similar Threads
crontab
creating a cron file
invoking jvm from other jvm
script problems
system.exit