Removing tokens from cmd line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing tokens from cmd line
# 1  
Old 05-30-2009
Removing tokens from cmd line

Hi everyone.
I am trying to develop my own shell,and i am in the part of redirection.
let's say the user gives as input
cat test > test2
in the array of arguments i want to keep only arg[0]=cat,arg[1]=test.
">" token is not an input file so cat cannot worka and test2 is output.how can i remove > and < from the array in which i keep the input that the user gives?
//sorry for my english...

Last edited by bashuser2; 05-30-2009 at 03:11 PM..
# 2  
Old 06-01-2009
I am not sure of your exact requirement ...But something like this u can use,...

Code:
par="$@"

pos=`echo $par | awk '{ for(i=1;i<=NF;i++) if($i==">" || $i=="<") print i }'`

will giv u the position of < or > .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: cmd. line:1: fatal: division by zero attempted

when i try the snippet in the console its working fine: ps awwwux | grep php-fpm | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' output: but when i try the bash script: #!/bin/sh # -*- sh -*- #... (3 Replies)
Discussion started by: danieloooo
3 Replies

2. Shell Programming and Scripting

Get tokens from line and put them into an array

I have a line like: IDNO H1 H2 H3 HT Q1 Q2 Q3 Q4 Q5 M1 M2 EXAM I would like to be able to access these tokens in such a way: echo $myline #displays IDNO Is this possible to do in a shell script? (3 Replies)
Discussion started by: afulldevnull
3 Replies

3. UNIX for Dummies Questions & Answers

passing input into a cmd line that's waiting for a response

Hi, I am writing a little script to update a parameters on JMQ. however the JMQ requires a "y" confirmation to be input as part of the cmd I am running. However I want run this script to offline with no input from a user. it works if a I create a file with with just y in it and pass that in... (3 Replies)
Discussion started by: shropshirehobbi
3 Replies

4. Windows & DOS: Issues & Discussions

Command works on CMD line but not in batch?

Hi All, This command works when I type it on but when I run the batch file it doesn't..any ideas why? attrib.exe * | find /c /v "" >filecount.txt (1 Reply)
Discussion started by: Grueben
1 Replies

5. UNIX for Advanced & Expert Users

SSH key works from CMD line not script

OK , .. This is an odd one. I have a new server and I need to have a tunnel open to it. I have this exact process running on a few others but this new one I just got is not allowing the script to connect. I set up my users account and ssh keys from the server that will host the tunneling i... (6 Replies)
Discussion started by: jeffsandman0035
6 Replies

6. Programming

How to take input from cmd line into file

Hi, I want to be able to write a simple program that takes in input from the command line. I;m am at the level of getchar and putchar. Any examples would be a great help thanks. I intend/prefer also to use the pipe command | eg: input | file1 ---------- Post updated at 04:08 PM ----------... (4 Replies)
Discussion started by: metros
4 Replies

7. Shell Programming and Scripting

2 CMD results on the same line while rexing in a loop

Folks, I have a 3 problems. In a sh script, I call a server name from a list and rex to a distant machine to get the boot date. for i in `cat list` do (echo "$i|"; /bin/rexsh $i -l bozo -t10 who -b | cut -d" " -f14-16) >>getBootTimes.out sleep 1 done The results are on 2 lines instead... (8 Replies)
Discussion started by: linux_lou
8 Replies

8. Solaris

Reset ILOM from cmd line

One of our T5220 console is not working & unable to login to ILOM , but system is up & running . is there a way to reset ILOM from command line ? (8 Replies)
Discussion started by: skamal4u
8 Replies

9. AIX

Yesterday's date without changing anything and in one cmd line ?

I have seen references in the forum about getting yesterday's date but it is either by changing something in the system (date, time zone, ...) or with more then one line of script cmds. How can I get yesterday's date without changing anything in the system and in one single command line ? (4 Replies)
Discussion started by: Browser_ice
4 Replies

10. Shell Programming and Scripting

works from cmd-line but not in script

hi I'm trying to query a directory, check it's the right directory, return the results into a text file, put text file into an array and navigate the subdirectories and delete contents. find `pwd` -type d | grep TESTINGDIR > dirList.txt The txt file is created from the cmd-line but not in... (4 Replies)
Discussion started by: OFFSIHR
4 Replies
Login or Register to Ask a Question