Sponsored Content
Homework and Emergencies Homework & Coursework Questions Make a file accept only two arguments from the command line Post 302936003 by ProgMan2015 on Saturday 21st of February 2015 11:47:26 AM
Old 02-21-2015
Progress

ok I made some progress:

Code:
 
 #!/bin/ksh
 #Reroute to directory of used files
 cd /class/
 #Create function to handle exit function
 function usage{
 echo "Usage $0 inputfile outputfile"
 echo "The inputfile must have the text \"${must_have_text}\""
 exit 1
 }
 #Make the asg6s accept only two arguements
 if [ $# -ne 2 ]; then
 echo "Does not equal two arguments"
 usage
 fi
 #Creates file containing Message Holder
 #Have a variable for the message
 must_have_text="Message Holder"
 #Determine if first argument is empty or null
 #Create variables
 infile=$1
 outfile=$1
 if [ ! -f "${infile}"]; then
 echo "File ${infile} does not exist"
 usage
 fi
 if [ $(grep -c "${must_have_text}" ${infile}) -eq 0; then
 echo "${infile} must have 1 or more times the text ${must_have_text}"
 usage
 fi
 cp ${infile} ${outfile}

I keep getting this error though: ./asg6s: line 3: syntax error at line 6: `echo' unexpected

Last edited by ProgMan2015; 02-21-2015 at 12:54 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make new arguments for echo command

Hi everybody, i want to make an argument at echo command that takes a alpharithmetic and returns it reversed. How this can be done? plus what makefile changes are needed (0 Replies)
Discussion started by: Panteras
0 Replies

2. Shell Programming and Scripting

How to read arguments to make command

In the make file update updateq: ------------------- ---------- i want the makefile to display some messages when user gives "make update", but totally quite wehn user enters "make updateq". Can u tell me how to read these argument in makefile. $1 doesnt work:( (3 Replies)
Discussion started by: vikashtulsiyan
3 Replies

3. Homework & Coursework Questions

I need to make a script that has 4 command line arguments to function properly.

I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
Discussion started by: Wookard
3 Replies

4. Homework & Coursework Questions

trouble understanding file option and command line arguments

Hi, I am creating a program with the C language that simulates the WC command in Unix. My program needs to count lines, bytes and words. I have not added the code to count bytes and words yet. I am having trouble understanding what the file option/flag '-' does. I can not visualize how it moves... (1 Reply)
Discussion started by: heywoodfloyd
1 Replies

5. Shell Programming and Scripting

ksh script that will accept arguments

Hi, I am not very skilled using ksh scripts. How do I create a ksh script that will accept arguments and use them in the script ? I need to make this: Run this command with this argument: ./mykshprogram.ksh madsen and sometimes I need to do this: Run the ksh again with 2... (3 Replies)
Discussion started by: hasselhaven
3 Replies

6. UNIX for Dummies Questions & Answers

script unix which accept two arguments

does anyone can help me with this homework, please..I am beginner in linux and I don't how to do it :( Create a script scanner.sh which will accept two arguments: the first argument is the DNS name or the IP address of a system, or a network address or an IP range, the second argument is... (1 Reply)
Discussion started by: gennyy
1 Replies

7. Shell Programming and Scripting

Perl : accept multiple user entered command line arguemnts

I am trying to create a script that will accept multi input from the user (really just me), then execute those command on a remote device. My question is if the I enter "No" at the confirmation point "Are these statements correct y or n ?", what is the best way to go back and start over ? I... (3 Replies)
Discussion started by: popeye
3 Replies

8. Shell Programming and Scripting

How to accept command line argument as character or text if number is entered?

Hello Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies

9. UNIX for Dummies Questions & Answers

Command - filename as arguments - make executable to all users.

Edit: Sorry. Mistakenly posted - please delete (3 Replies)
Discussion started by: Reddax
3 Replies

10. Programming

Make a file accept only two arguments from the command line

DELETED (2 Replies)
Discussion started by: ProgMan2015
2 Replies
command(1)						      General Commands Manual							command(1)

NAME
command - execute a simple command SYNOPSIS
command_name [argument ...] DESCRIPTION
enables the shell to treat the arguments as a simple command, suppressing the shell function lookup. If command_name is not the name of the function, the effect of is the same as omitting command. Operands recognizes the following operands: command_name The name of a HP-UX command or a shell built-in command. argument One or more strings to be interpreted as arguments to command_name. The command is necessary to allow functions that have the same name as a command to call the command (instead of a recursive call to the function). Nothing in the description of is intended to imply that the command line is parsed any differently than any other simple command. For example, is not parsed in any special way that causes or to be treated other than a pipe operator or semicolon or that prevents function lookup on b or c. EXTERNAL INFLUENCES
Environment Variables determines the search path used during the command search. RETURN VALUE
exits with one of the following values: o If fails: 126 The utility specified by the command_name is found but not executable. 127 An error occurred in the utility or the utility specified by command_name is not found. o If does not fail: The exit status of is the same as that of the simple command specified by the arguments: command_name[argument ...] EXAMPLES
Create a version of the command that always prints the name of the new working directory whenever it is used: cd() { command "$@" >/dev/null pwd } Circumvent the redefined command above, and change directories without printing the name of the new working directory: SEE ALSO
getconf(1), sh-posix(1), confstr(3C). STANDARDS CONFORMANCE
command(1)
All times are GMT -4. The time now is 02:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy