Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6892325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:31:16+00:00 2026-05-27T06:31:16+00:00

My assignment asks that: Create a directory ~/UnixCourse/scriptAsst . Turn the two-line version, above,

  • 0

My assignment asks that:

Create a directory ~/UnixCourse/scriptAsst. Turn the two-line version,
above, of the substitution commands into a shell script, subst1 taking
three parameters: the string to be replaced the string with which to
replace it the name of the file in which to make the substitution.

For example,

`~/UnixCourse/scriptAsst/subst1 foo bar myFile.txt`

should replace all occurrences of foo in the file myFile.txt by bar, leaving the
original file as myFile.txt.bak.

Similarly,

`~/UnixCourse/scriptAsst/subst1 abc "" aardvark.dat`

should remove (replace by the empty string) all occurrences of abc in the file aardvark.dat with nothing, leaving the original file as aardvark.dat.bak.

My code that I came up with is:

#!/bin/bash

set p1 = "$1"
shift
set p2 = "$1"
shift
set p3 = "$*"

echo $p1
echo $p2
echo $p3

if grep "$p1" "$p3" > /dev/null; then
mv "$p3" "$p3.bak"
sed "s/$p1/$p2/g" "$p3.bak" > "$p3"
fi

When I try to run:

./subst1 foo bar myFile.txt

I keep getting:

grep: : No such file or directory

Please help!! What am I doing wrong??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:31:16+00:00Added an answer on May 27, 2026 at 6:31 am

    or use the parameters directly…

    #!/bin/bash
    
    echo $1
    echo $2
    echo $3
    
    if grep "$1" "$3" > /dev/null; then
      mv "$3" "$3.bak"
      sed "s/$1/$2/g" "$3.bak" > "$3"
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a homework assignment that asks me to create a calculator that
hey guys, i have a c++ programming assignment that asks me to create a
I have a homework assignment that asks to create an order form. The order
I have an assignment that asks me to retrieve delimited text from form values.
Our homework assignment asks us to prove that the Java LinkedList implementation is doubly-linked
A homework assignment asks me to implement a program that counts the words in
I'm working on a homework assignment that basically asks us to parse a DNS
I am working on an assignment that asks me to implement an AVL tree.
I'm very new to XML and XSLT. I have a homework assignment that asks
I am working on an assignment where one of the problems asks to derive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.