Too simple to search for


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Too simple to search for
# 1  
Old 10-21-2006
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  
Old 10-21-2006
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  
Old 10-21-2006
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  
Old 10-21-2006
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 02:16 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Having trouble with simple grep search

I have a text file (allWords.txt), that I would like to search through. Here is a snippet of what it looks like... a aah aahed aahing aahs aardvark aardvarks aardwolf ab abaci aback abacus abacuses abaft ...... I would like to use the grep search to search, line by line, for... (8 Replies)
Discussion started by: blackvelvet
8 Replies

2. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Simple awk search problem

Hello; we have : awk '/reg_exp/,0/ prints every line after the first occurrence of "reg_exp" But if I want to print rest of the lines AFTER the last occurrence of "reg_exp", how would I do it ?? Tried : awk ' ! (/reg_exp/,0)' But it errored... Thank you for any... (5 Replies)
Discussion started by: delphys
5 Replies

5. Shell Programming and Scripting

How to do a simple awk search?

Hello I am trying to do global search on access log files for a date and for either 'Error|error' string ls -lrt *access* | grep "Sep 23" | awk '{print $9}'|xargs awk '/23\/Sep\/2011/ && /Error/ || /error' Above matches All lines with 'error' as well unfortunately. Is there a... (6 Replies)
Discussion started by: delphys
6 Replies

6. Shell Programming and Scripting

Simple (not for me) string search script

hi there, I am a complete newb to bash but am going to try and make a script to help me seach text files for strings of interest, any help that one of you gurus could pass on will be greatly received!! I want to write something like: in "text1.txt" find "string1" and copy out the line... (7 Replies)
Discussion started by: jumbo999
7 Replies

7. UNIX for Dummies Questions & Answers

Simple search pattern help

Hi I need to define a pattern that will match an open square bracket, a series of numbers fro 1 to 4 digits in length and a close square bracket. Examples of the numbers I will need to find are: or or or I am using BBEdit to search, and BBEdit uses the standard GREP search... (1 Reply)
Discussion started by: alisamii
1 Replies

8. Shell Programming and Scripting

Simple Search and Replace - Revisited

I have a ascii file with lines like this: 240|^M\ ^M\^M\ Old Port Marketing order recd $62,664.- to ship 6/22/99^M\ when this record gets loaded into my database, the \ is stored literally and so the user sees carriage return \ (hex 0D 5C) when what i need is carriage return line feed (hex 0D... (1 Reply)
Discussion started by: Brandt
1 Replies

9. UNIX for Dummies Questions & Answers

Simple? Search replace

in vi, if i type ctrl-J, i can shift the next line up to the current line. I need to do this whenever a specific string exists (in particular ^M) ,however i have not been able to find a way to do this in vi, sed, or awk seems simple enough. can someone help me? thanks in advance (9 Replies)
Discussion started by: Brandt
9 Replies
Login or Register to Ask a Question