LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-26-2004, 11:49 AM   #1
Squeak2704
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
command line args in a countdown


I need to write a shell script that will take the number of command line arguments and count them down (like 6 5 4 3 2 1) then tell you the last command line argument that the user entered. It says to count them down using a shift builtin in a loop. I am unsure how to do this. I have used the while command and cannot get that to work. Here is my script for the while....
let $# = number
while ["$number" - ge 1]
do
echo $number
sleep 1
let $# ="$number - 1"
done
echo the last command line argument you entered was $1

do I have to let $# = number or can I just use $# ? I have tried both ways and cannot get them to work....or am I doing the wrong thing completely?
also, this gives the first command line arg....how do you get the last??
thanks a lot..
 
Old 04-26-2004, 12:27 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Code:
#!/bin/sh

while test $# -gt 0 ; do
	echo $#
	ARG=$1
	shift
done
echo "Last argument: $ARG"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
processing command args in bash slzckboy Programming 10 09-28-2005 04:49 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
51 characters only in the 1st Line of command line eggCover Linux - General 2 07-29-2004 01:28 PM
Bash script; command and args in variable. magjo813 Programming 2 02-16-2004 09:22 AM
>>> control mplayer with command args??? nibjb Linux - Software 0 07-16-2003 11:09 PM


All times are GMT -5. The time now is 05:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration