LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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: Debian
Posts: 2,536

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

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


Reply



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 16 10-18-2017 03:12 AM
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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:57 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration