Sponsored Content
Homework and Emergencies Homework & Coursework Questions (t)csh command line arguments issues Post 302741113 by kcoll025 on Friday 7th of December 2012 12:13:27 PM
Old 12-07-2012
(t)csh command line arguments issues

1. The problem statement, all variables and given/known data:

create a shell script, chExt.sh that takes one or more parameters, where the first is a desired extension and the remainder are names of files to be renamed. For each file in the command line, this script should rename the file, as above, if the file exists or print the error message described in the previous step if the file does not exist.
For example,

ls > crocodile.foo
echo bark > dingo.bar
./chExt.sh dat crocodile.foo bogusName.foo dingo.bar

should result in crocodile.foo being renamed crocodile.dat, an error message "bogusName.foo: No such file", and dingo.bar being renamed dingo.dat.




2. Relevant commands, code, scripts, algorithms:
Code:
#!/bin/csh

set ext = $1
shift

foreach file ( $*  )
# with double quotes show all to one name
# with single quotes foreach: No match.
# without quotes separate king cobra.dat into 2 files
echo "original input" "$file"
set oldName = "$file"
if ( -e "$oldName") then
set newName= (`echo "$oldName" | sed "s/\(.*\)\..*/\1/"`)
set newName = "$newName"."$ext"

if ("$file" != "$newName") then
mv "$file" "$newName"
endif
else
    echo "$file"": No such file"
endif


3. The attempts at a solution (include all code and scripts):
Line 6 : foreach file ( $* )
I need it to be able to read in 'cpp' 'file.dat' 'king cobra.dat'
as 3 variables, but i can only get it to do 'king' and 'cobra.dat'
i tried putting double quotes around "$*" in my foreach but that causes the variable to be 'file.dat king cobra.dat' as one long variable name


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Old Dominion University, Norfolk, Virginia, USA, Prof. Zeil, CS252<http://www.cs.odu.edu/~cs252/>


please help ASAP, it's due by tonight and i've been stuck on this for days now.

Last edited by Corona688; 12-07-2012 at 02:42 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

command line arguments

Hi How to pass multi line text as a command line argument to a program. (i.e) ./a.out hi this is sample 0 file1 where hi this is sample should be stored in argv 0 in argv and so on... (3 Replies)
Discussion started by: bankpro
3 Replies

2. UNIX for Dummies Questions & Answers

arguments in command line

Hi all, How many arguments can we pass while testing a prgm at command line.. I encountered an issue while passing 10 arguments. For $10 its taking argument passed for $1 followed by 'zero'. can we pass more than 9 arguments /Is there any other way. Thanks, rrs (6 Replies)
Discussion started by: rrs
6 Replies

3. Shell Programming and Scripting

command line arguments

-------------------------------------------------------------------------------- I have this while loop and at the end I am trying to get it to tell me the last argument I entered. And with it like this all I get is the sentence with no value for $1. Now I tried moving done after the sentence... (1 Reply)
Discussion started by: skooly5
1 Replies

4. Shell Programming and Scripting

Getting error in command line arguments

Hi, When i am running the following script 1.sh (without giving the command line arguments) then i am getting the following error. if then echo "UID and PWD are correct" elif then echo "Either UID or PWD is wrong. Please check your UID and PWD" else echo "UID and PWD can't be blank"... (9 Replies)
Discussion started by: sunitachoudhury
9 Replies

5. UNIX for Dummies Questions & Answers

Command line arguments.

I am working on a script wherein i need the user to enter the Build ID for eg:the command line will show enter the build ID Now on entering the build ID it should be assigned to @ARGV. How can this be done.? (1 Reply)
Discussion started by: Varghese
1 Replies

6. UNIX for Dummies Questions & Answers

command line arguments

hi, can someone how to accept command line arguments as a variable using in script? like: ./scriptname arguments by accept arguments, I can use it in my script? thx! (1 Reply)
Discussion started by: ikeQ
1 Replies

7. Shell Programming and Scripting

command line arguments

hi,,,, I want to create a command prompt, for example "prompt>", so my prompt need to handle commands, for example "prompt>cmd", so i want to know how to get arguments for my own commands cmd, i.e. default argc should contain arguments count and argv should point to the argument vector i.e, for... (2 Replies)
Discussion started by: vins_89
2 Replies

8. Shell Programming and Scripting

Help on command line argument in csh

HI , I am new to csh. I need to pass some command line arguments like ./abc.sh -os Linux -path abc -tl aa -PILX 1 I have defined the loop as shown below. But its taking "-os" switches as arguments. Its treating them as arguments. How to resolve it? while ( $#argv != 0 ) switch ($argv) ... (7 Replies)
Discussion started by: vineet.dhingra
7 Replies

9. Shell Programming and Scripting

Command line arguments for addition

Hi all, I am trying to write a code for addition of n numbers which will be passed by the user as command line arguments. I wrote the following code. add=0 for (( i = 1 ; i <= $# ; i++ )) do add=`expr $i + $add` done #echo "sum is : $add" input : $./add.sh 12 32 14... (7 Replies)
Discussion started by: PranavEcstasy
7 Replies

10. UNIX for Beginners Questions & Answers

Loop with command line arguments

Ubuntum, Bash version: 4.3.46 Hi, how can I create a loop where the command line arguments change (increase) and every time the number of arguments is different ? ### I have many gene names... that mean gene1=$2, gene2=$3, ...... geneN=$N+1 ### some time the number of gene is 25, other... (7 Replies)
Discussion started by: echo manolis
7 Replies
EVENTS(1)																 EVENTS(1)

NAME
events - stream events from or to a CORBA EventChannel SYNOPSIS
events [-n channel-name] [-s] [-h] [-ORBparameter value] [channel-uri] DESCRIPTION
events streams events from an event channel to standard output, or (-s) from standard input to an event channel. Events are streamed in raw binary form, accompanied by a timestamp. When the stream is played back into a channel, the timestamps are used the replicate the original delays between the messages. The main use for this command it to record sets of events and play them back later for testing. Recording example: events corbaname::#EventChannel > test.dat Playback example: events -s corbaname::#EventChannel < test.dat OPTIONS
-n channel-name The CORBA Name Service name used to look up the EventChannel CORBA object. Format for channel-name: [CONTEXT-ID[.CONTEXT-KIND]/]*OBJECT-ID[.OBJECT-KIND] Examples: foo, foo.bar, foo.bar/baz/qux, foo/bar/baz.qux. The default is EventChannel -s Supply mode. Read events from standard input. -h Display a short summary of command-line options. -ORBparameter value Standard omniORB options. see omniORB documentation for details. This option is commonly used to set the omniORB traceLevel, in or- der to get more detailed output. Example: -ORBtraceLevel 5 ENVIRONMENT VARIABLES
OMNIORB_CONFIG The location of the omniORB configuration file. COPYRIGHT
Copyright (C) 2004,2005 Alex Tingle. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. EVENTS(1)
All times are GMT -4. The time now is 02:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy