The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics 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 10:24 AM
Simple to you not simple to me pattern matchin help aleks001 Shell Programming and Scripting 0 07-22-2007 10:06 PM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 01:03 PM
Simple Search and Replace - Revisited Brandt Shell Programming and Scripting 1 04-23-2004 10:45 AM
Simple? Search replace Brandt UNIX for Dummies Questions & Answers 9 01-17-2004 01:51 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2006
spudtheimpaler's Avatar
spudtheimpaler spudtheimpaler is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 8
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.
  #2 (permalink)  
Old 10-21-2006
spudtheimpaler's Avatar
spudtheimpaler spudtheimpaler is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 8
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.
  #3 (permalink)  
Old 10-21-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #4 (permalink)  
Old 10-21-2006
spudtheimpaler's Avatar
spudtheimpaler spudtheimpaler is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 8
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 01:16 PM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0