How to find the last argument in a argument line?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find the last argument in a argument line?
# 1  
Old 06-20-2008
How to find the last argument in a argument line?

How to find the last argument in a argument line?
# 2  
Old 06-20-2008
The special variable $# would tell you
# 3  
Old 06-20-2008
Computer solution

hey this is the solution

for i in $*; do test $i ;done
print $i
# 4  
Old 06-20-2008
or
Code:
echo $@ | awk '{ print $NF }'

if the last argument is not string of words with spaces in it
# 5  
Old 06-20-2008
Hi,

The below command will display the last argument

echo $*|awk '{print NR, $NF}'
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find: missing argument to `-mtime'

this find command works when using manually on the command line -- $ ls -latr file*.log -rw-r--r-- 1 oracle dba 75 Jan 4 05:00 file_2.log -rw-r--r-- 1 oracle dba 75 Jan 4 05:00 file_1.log $ $ find . ! -name -prune -type f -name "file*.log" -daystart -mtime 2 ./file_1.log ./file_2.log $... (8 Replies)
Discussion started by: wtolentino
8 Replies

2. UNIX for Beginners Questions & Answers

Command line argument

Hi Guys, I'm trying to work out how to add a command line argument inside single quotes. Would anyone be able to help please as I'm going mad :) I want to be able to place the filename on command line and it then be used in a script but it needs to have quotes surrounding it. Thanks in... (4 Replies)
Discussion started by: mutley2202
4 Replies

3. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

4. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

5. Shell Programming and Scripting

Passing argument on find command

Hi, I'm trying to pass the variable in the find command like below a=log.20111114 find /apps/file3_logs/env3/ -name '$a' -exec ls -lrt {} \; but it's not working thanks in advance. Regards Thelak (3 Replies)
Discussion started by: ajithbe
3 Replies

6. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

7. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

find: No match due to find command being argument

I am using csh and getting the error "find: No match." but I cannot figure out why. What I am trying to do is set the find command to a variable and then execute the variable as a command. I ran it through a debugger and it looks like $FIND is getting set but the find command can not actually be... (2 Replies)
Discussion started by: mst3k4l
2 Replies

9. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

10. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies
Login or Register to Ask a Question