Sponsored Content
Homework and Emergencies Homework & Coursework Questions Shell Scripting with Arguments Post 302686509 by dw15 on Tuesday 14th of August 2012 06:19:42 PM
Old 08-14-2012
Shell Scripting with Arguments

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

Problem 1:

I need to create a shell script the takes three arguments and echo's out "There once was a ____that____who like to_____"
The arguments go where the blanks are.



Problemt 2:

-Do an LS and store the listings in a file

-Open the file in emacs.

-create a macro that converts that single line to the command "mv file.txt file.dat"

-run the macro over the entire file.

-chmod +x the listing file

-run the file as a script.





2. Relevant commands, code, scripts, algorithms:

For problem one my instructor provides me with this example:

echo -n "some argument"

echo $1

how I've been reading it is like a C++ code

cout << "Some argument"

cin >> argurment

3. The attempts at a solution (include all code and scripts):

For problem 1 I've tried it many different ways, this is my latest attempt:

echo -n "There once was a "
echo $1
echo -n "that "
echo $2
echo -n "who liked to "
echo $3
echo -n "There once was a " $1 " that " $2 " who liked to " $3

I believe my teacher wants the echo to be just on one line. I dont want the code given to me, I'm really just hoping someone can show me what I'm doing wrong so I can correctly do it. There is a part b to this question and if I understand what I'm doing wrong in part a im positive I can do part b.

For problem 2 I've run an ls and moved all .txt files to a new file called change. From there I created a macro that searched for all .txt and replaced them with .dat. I'm having a hard time understanding how to mv this data to replace the old .txt files in the directory I copied them from.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Portland Community College, Hillsboro, OR, United States, Mike Noel, CS 140u Intro to Unix

Link -PCC Class Schedule

Last edited by dw15; 08-14-2012 at 08:15 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Arguments to a shell program

Hi List, Is it possible to pass one argument to a shell program eg) there is a shell program abc which takes one arguments abc one Due to some reasons I pass abc one two Now one,two must be considered as "one" argument to the shell programs. Any suggestions,hints are welcome. ... (3 Replies)
Discussion started by: csvenkata
3 Replies

2. Shell Programming and Scripting

Shell script with arguments

Hi All, I need some help/ideas in coming up with a shell script. Basically, the script should install 1 or 2 or 3 packages based on the input arguments. For example, if I type in pkgscript.sh a1 a2 a3, it should install all the 3 scripts and pkgscript.sh a1 should install only a1. If a... (3 Replies)
Discussion started by: sankar6254
3 Replies

3. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

4. Shell Programming and Scripting

Bash Shell - # of arguments

Hi!, How can I check the number of arguments passed from the shell in a bash shell ? (1 Reply)
Discussion started by: DNAx86
1 Replies

5. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

6. Shell Programming and Scripting

Using arguments in Shell script

Hello, I have to make a shell script doing that : the program tests if there is an argument, if there is it checks whether this is a directory or not, If it is it opens it. for any .c file in the directory it prints 2 lines in the screen : the dependence line of the .o and compiler commend... (1 Reply)
Discussion started by: dekl
1 Replies

7. Shell Programming and Scripting

sub arguments to shell script

Hi, I have a shell script, when run it i get a prompt to enter arguments say 1 for doing my next task otherwise q for quit. What I am trying to do is run the shell script with the argument passed in however it does not seem to work. This is what I did ./test.sh 1 Instead it printed the line... (6 Replies)
Discussion started by: aqua9
6 Replies

8. Shell Programming and Scripting

Shell scripting with passing arguments

Hi All, I am using the script for creating local queue and passing the arguments while running the script as below n=0 while do e=`expr $n + 3` echo 'DEFINE QL('$e') MAXDEPTH('$6') MAXMSGL('$7') DEFPSIST('$8') '$9'' | /apps/mqm_opt/bin/runmqsc $2 n=`expr $n + 1` done Running the... (5 Replies)
Discussion started by: Anusha M
5 Replies

9. Shell Programming and Scripting

Scripting with arguments for ping command

This is the script I already have but I have problems with two arguments the first argument -t , I want to count 200 by the last digit of the IP address for example when I run the script ./ping.sh -t 17, the output would be192.168.0.217 is upThe second arguments --up won't work. Could anybody... (1 Reply)
Discussion started by: Roggy
1 Replies

10. UNIX for Beginners Questions & Answers

Beginner at bash scripting - need help with passing arguments

I at the moment, making a simple bash script, capable of setting up an workspace for me, so i don't have to do it manually.. Problem is though i can't seem to provide the bash script any argument, without running into my error checks, checking for input... Here is the code: #!/bin/bash... (7 Replies)
Discussion started by: kidi
7 Replies
escape(1)                                                       Mail Avenger 0.8.3                                                       escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 10:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy