Online since 2002. Over 3300 puzzles, 2600 worldwide members, and 270,000 messages.

TwistyPuzzles.com Forum

It is currently Fri Apr 18, 2014 9:23 am

All times are UTC - 5 hours



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Please, need help with linux
PostPosted: Wed Nov 01, 2006 4:02 pm 
Offline
User avatar

Joined: Thu Dec 15, 2005 4:25 pm
Location: Madrid-Spain
We have started programming a bit on linux at university. Well, they want us to know by ourselve programming.......

I need to program into a command file a little program who receive a number of arguments, and displayed them in opposite direction. I have thought on doing in that way:

echo "In opposite way:"
NUM=$#
while
test $NUM -ne 0
do
echo $($NUM)
NUM=expr $NUM - 1
done

Could anybody please tell me what I'm doing bad?

Thanks you very much

_________________
Life is like a Rubik's Cube.... it always has a solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 4:51 pm 
Offline

Joined: Tue Oct 07, 2003 10:00 pm
It would help to know which shell you're using (echo $SHELL).

Try it this way:
echo ${!NUM}
NUM=`expr $NUM - 1`


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 5:06 pm 
Offline
User avatar

Joined: Thu Dec 15, 2005 4:25 pm
Location: Madrid-Spain
DANG STEFAN! YOU'RE MY GOD NOW!

eheheheheh

It works!!!!!!

Thanks you very much dude!

Now, could you please explain me the differences between using $ for displaying a variable's content and using ! ?

Thanks you again man!

:):):)

_________________
Life is like a Rubik's Cube.... it always has a solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 5:09 pm 
Offline

Joined: Tue Oct 07, 2003 10:00 pm
I wasn't your god before this??? Pffft.

From the bash manpage:

${parameter}
The value of parameter is substituted. The braces are
required when parameter is a positional parameter with
more than one digit, or when parameter is followed by a
character which is not to be interpreted as part of its
name.

If the first character of parameter is an exclamation point,
a level of variable indirection is introduced. Bash uses
the value of the variable formed from the rest of parameter
as the name of the variable; this variable is then expanded
and that value is used in the rest of the substitution,
rather than the value of parameter itself. This is known as
indirect expansion. The exception to this is the expansion
of ${!prefix*} described below.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 5:11 pm 
Offline
User avatar

Joined: Thu Dec 15, 2005 4:25 pm
Location: Madrid-Spain
Stefan, it's seems I'm using a father shell.

/bin/sh

Just another question,

If I accidentally delete a file with rm (thinking that rm is a command for RenaMe instead of ReMove.. stupid me heheheh), is there any bin folder or something like that where I can recover the file from?

In example, when working on a Vi editor, There are many buffers where I can recover the info just typing u command. Is there anything similar in unix?

Thanks you again!

_________________
Life is like a Rubik's Cube.... it always has a solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 5:19 pm 
Offline
User avatar

Joined: Thu Dec 15, 2005 4:25 pm
Location: Madrid-Spain
Just a last thing stefan.

Could you please show me the link where you take that sentences off?

Thanks! ;)

_________________
Life is like a Rubik's Cube.... it always has a solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 6:10 pm 
Offline

Joined: Tue Oct 07, 2003 10:00 pm
rastarubik wrote:
In example, when working on a Vi editor, There are many buffers where I can recover the info just typing u command. Is there anything similar in unix?


As far as I know, not by default. Here at our university we use unix and if I delete a file then it's gone, all I can do is ask the system admins to restore it from backup if it there is one (they backup once a day here). Better ask your admin what is available for the system you use.

Quote:
Could you please show me the link where you take that sentences off?

Like I said, it's from the manpage. If you want to see documentation for a command, just type "man command" in the command line, e.g., "man bash" (without the quotes, of course).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 6:13 pm 
Offline

Joined: Tue Oct 07, 2003 10:00 pm
When I say "it's gone" I mean its entry is removed from the directory and the part on the hard disk where the actual data is probably gets overwritten real fast because someone else (or I) writes a new file and overwrites the data on the hard disk. If you're only using it yourself maybe you can "undelete" the file but I don't know anything about that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Forum powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group