The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 06:24 AM
Simple to you not simple to me pattern matchin help aleks001 Shell Programming and Scripting 0 07-22-2007 07:06 PM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 09:03 AM
Simple Search and Replace - Revisited Brandt Shell Programming and Scripting 1 04-23-2004 07:45 AM
Simple? Search replace Brandt UNIX for Dummies Questions & Answers 9 01-16-2004 09:51 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-2006
spudtheimpaler's Avatar
Registered User
 

Join Date: Oct 2006
Posts: 8
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Too simple to search for

Hey. I'm just getting started with scripting and although i will admit i haven't searched the forum yet, i think it would be a waste of time. It really will be very simple.

I want to enter a list of arguments after my script with the last being the filename. (not the first, as this is part of the requirements)

I so far have

Code:
var=$#
filename=$var
echo "last argument is $filename"
Now i have put every variation i can think of around the second lines var in order the change the value of filename to be from the location in the list of arguments to the argument itself, ie if i put

sh script hi there smelly

smelly is the last argument.

i want the filename to take on the value of the file smelly, not the value 3 (3rd argument)

if i put sh script hi there scriptfile1
where scriptfile1 exists and is the file i want to to point to, it still has argument 3. Whilst I would rather have it point to a file that already exists, i don't mind if it creates a new tempfile, (and will do checks on if files exist once i can get this sorted) i would just like to know how i can have it point to a filename rather than the argument number.

I'm sure i've made that a lot more difficult that it is, but any advice would be appreciated.

Regards, and thanks for your time!

Mitch.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-21-2006
spudtheimpaler's Avatar
Registered User
 

Join Date: Oct 2006
Posts: 8
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
clarification

Ok I have thought of a way to clarify my question.

my last argument from many will be a filename

say I have a script

Code:
touch /tmp/$#
will create a file /tmp/3

Whilst I'm not surprised by this, how can I change it so that $# doesn't give me the number of arguments, but the argument at position $#

Hope that clears things up.

Mitch.
Reply With Quote
  #3 (permalink)  
Old 10-21-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,205
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by spudtheimpaler
Hey. I'm just getting started with scripting and although i will admit i haven't searched the forum yet, i think it would be a waste of time.
Well, we don't think it would be a waste of time. That is why the rules state:
(5) Search the forums database with your keywords before asking.

Had you searched the forums maybe you have found printing last argument in shell script or one of the dozens of other threads that answer your question. Please give the search function a try next time.
Reply With Quote
  #4 (permalink)  
Old 10-21-2006
spudtheimpaler's Avatar
Registered User
 

Join Date: Oct 2006
Posts: 8
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thanks for the reply. Although I'm sure you wont believe me, I read the rules before I posted.

After posting the question I realised that it wasn't clear. In the example I used above, I was after the last argument (which the thread you suggested does show how to do) but my question was as per the second article. That is to say it could be anywhere within the argument list. If i were to search, the terms I would be using would be position, argument, file, all terms ubiquitous to most threads. That is why i chose against searching.

Thanks for your response.

Mitch.

P.S. I am a nice guy, and understand where you are coming from. I know from experience what it is like partaking in forums where people ask questions that have been asked a hundred times before. I didn't just ignore the search feature off the cuff. Sorry if I pi**ed you off.

Last edited by spudtheimpaler : 10-21-2006 at 10:16 AM.
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 09:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102