C shell deciphers someones code & argv


 
Thread Tools Search this Thread
Top Forums Programming C shell deciphers someones code & argv
# 1  
Old 02-25-2011
Question C shell deciphers someones code & argv

I’m trying to work off of someone else code they gave me as an example but they are gone! I’m trying to pretty much write a wrapper of several different scripts.
They use argv[1]…I keep on thinking the next one should be argv[2] ect. I’m not sure if maybe its different in PERL maybe if that’s true? Or maybe the command lines are mutually exclusive? Then in my perl script a lot of my options are optional. I couldn’t do an if statement b/c I’m not sure which ones will be called! I almost need to append to the command file if they are selected. But I don’t think doing something like
Code:
$perl >> -lnf $lnf  would work? Do u have any idea?

set arg=$argv[1]
  shift argv
  switch ($arg)
   case "-alf":
      set dir = `echo "$argv[1]"`
    breaksw
    case "-cell":
      set cell = `echo "$argv[1]"`
      set perl = ${WARD}/bin/lnf2alf.pl -cell $cell
    breaksw
    case "-o":
      set out = `echo "$argv[1]"`
      $perl >> -o $out
    breaksw
    case "-lnf":
      set lnf = `echo "$argv[1]"`
      $perl >> -lnf $lnf
    breaksw
      case -h:
   case --help:
    default:
    goto help
    breaksw
  endsw
  shift argv
end

${WARD}/bin/lnf2alf.pl -cell $cell


Last edited by fpmurphy; 02-25-2011 at 09:43 PM..
# 2  
Old 02-26-2011
The trick is shift argv This pops the first element off the array, like:

Code:
# before shift
[ bog, flar, narm, fleeb ]
# after shift
[ flar, narm, fleeb ]

...so he can just keep using argv[1].

Perl has shift too. So do most shell languages actually.

Last edited by Corona688; 02-26-2011 at 01:08 PM..
# 3  
Old 02-27-2011
hey thanks! I'm not to familar with c shell was pretty much using google as a resource. Someone just told me it is like unix but it is in a script. Not many I people I work with have used C shell. I'm trying to write a wrapper. My user has several optional inputs..is there a shorter way to do what I need to do w/o lots of if statements?
so I have a perl file I will execute..but lots of optional user inputs. So..
$file.pl -out <file> -in <file> -dir <path> -dir2 <path2>
so I'd have several different combinations my script could be!
I could do it with several if statments but is there an easier way? I know you can append to a input of a file with <<..is there something like that? sorry for the maybe dumb question.
# 4  
Old 02-27-2011
Quote:
Originally Posted by carbuncle11
hey thanks! I'm not to familar with c shell was pretty much using google as a resource. Someone just told me it is like unix but it is in a script.
I have no idea what they were even trying to say. The C-shell was made in imitation of C but they didn't really succeed.

The C-shell isn't liked very much because of it's many limitations, problems, and general strangeness(see Csh Programming Considered Harmful for only some of the reasons we want to discourage its use), and many systems I've dealt with didn't even have it by default. Most folks I notice asking questions on it here only do so because they're forced to do so. If you want to learn a real shell that'll actually work on a lot of systems, check out some variety of Bourne or Korn shell.
Quote:
Not many I people I work with have used C shell.
Not surprising.
Quote:
I'm trying to write a wrapper.
In what? For what?

Last edited by Corona688; 02-27-2011 at 10:37 PM..
# 5  
Old 02-27-2011
Yeah if I didn't have to write in c shell I wouldn't! my boss is requireing it. I don't have much say in the matter. That is how they do all there scripts. Its a wrapper that calls a tcl & perl script. lol..general strangeness.
# 6  
Old 02-27-2011
Usually you'd parse arguments one by one and use a big case statement for switches, maybe aided by the getopt utility.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Passing Username & password through shell script to java code

Hi, I have a shell script (script.sh) in which we are calling java code which asks for Username: Password: for authentication purpose currently we are passing the credential manually and run the script. but I am trying echo -e "user_id\npassword" | script.sh but its not... (1 Reply)
Discussion started by: rakeshtomar82
1 Replies

3. Shell Programming and Scripting

Argv not found (script shell)

I don't know whether it is possible that I ask for help concerning a shel sscript that i wrote and which is not working. So here is my shell script: #! /bin/bash if($#argv != 1) then echo "hoge" exit endif set tgtdir = ../../result set target = ${tgtdir}/s${argv}/1 set... (7 Replies)
Discussion started by: khaoula.youssef
7 Replies

4. UNIX for Dummies Questions & Answers

Implement the '&&' function in a shell

Hello, I'm currently implementing the && function in a shell using C. For example, if we input cmd1 && cmd2, then cmd2 executes only when cmd1 exits successfully. I'm thinking about: int main() { int i; char **args; while(1) { printf("yongfeng's shell:~$ "); args =... (5 Replies)
Discussion started by: Yongfeng
5 Replies

5. UNIX for Advanced & Expert Users

O argv, argv, wherefore art thou argv?

All of my machines (various open source derivatives on x86 and amd64) store argv above the stack (at a higher memory address). I am curious to learn if any systems store argv below the stack (at a lower memory address). I am particularly interested in proprietary Unices, such as Solaris, HP-UX,... (9 Replies)
Discussion started by: alister
9 Replies

6. Shell Programming and Scripting

argv usage in a korn shell script

I'm trying to count and display the variables on a command line #!/bin/ksh $# argv from command line: tryit2 this is a test returns : tryit2: 4: not found. (1 Reply)
Discussion started by: Bperl1967
1 Replies

7. Shell Programming and Scripting

Problem with call of Java Programm & return code handling & output to several streams.

Hello Everybody, thanks in advance for spending some time in my problem. My problem is this: I want to call a java-Programm out of my shell skript, check if die return code is right, and split the output to the normal output and into a file. The following code doesn't work right, because in... (2 Replies)
Discussion started by: danifunny
2 Replies

8. Programming

tcl-argv with switch & while

I was trying to deciper someone else code. I'm just learning tcl. I was a litte confused about the $argv. I was thinking it would be only a certain value in argv..but if say someone give the switch -cell and -path_to_ezqb is it right to have the second one $argv??? while ($#argv > 0) ... (2 Replies)
Discussion started by: carbuncle11
2 Replies

9. Shell Programming and Scripting

Shell Script to display function names (called & defined) in a C++ Source Code

Hello to all, I am looking for a way to display only the names of function (calls & definition) of a C++ source code.There is already a post related to this, but the script is to find the functions using a specific variable, and the replies are not that convincing since they cannot be used for... (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. UNIX for Advanced & Expert Users

any hackers? i need someones help

to get into an telephone account online :confused: (4 Replies)
Discussion started by: jackie8
4 Replies
Login or Register to Ask a Question