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 8898403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:36:27+00:00 2026-06-15T00:36:27+00:00

I am taking a intro to Unix class and am stuck on the final

  • 0

I am taking a intro to Unix class and am stuck on the final assignment. I need to write a script to change the file extension of a filename that is input when the script is run. The new file extension is also input when the script is run. The script is call chExt1.sh . Our first trial of the script is run as follows

./chExt1.sh cpp aardvark.CPP

The script is suppose to change the second input file extension to the file extension given in the first input. It is not suppose to matter what file extension is given with the file name or what file extension is given as the new extension, nor is it only for changing uppercase to lowercase. In hope to make this very clear if given the following:

./chExt1.sh istink helpme.plEaSe

The script would change helpme.plEaSe to helpme.istink . I have searched on this forum and in google and have had no look with trying the different examples I found. Below is some of the examples I have tried and what I currently have.
Current

#!/bin/sh
fileExtension="$1"
shift
oldName="$2"
shift
newName=${oldName%%.*}${fileExtension}
echo $newName

The echo is just to see if it works, and if I get it working I’m going to add an mv to save it.
Others that I have tried:

newName=`${oldName%.*}`
newName=`${oldName#.*}`
sed 's/\.*//' $oldName > $newName

I can’t seem to find some of the other sed I have used but they involved alot of backslashes and () with .* in there. I did not try the basename command cause I don’t know the file extension to be entered and all I the examples I saw required that you specify what you wanted removed and I can’t. I did not list all the different quote variations that I used but I have tried alot. My instructions say to use the sed command since we should know how to use that from class but when I try to do it I don’t isolate just the ending of the file and I believe (cause it takes so long to finish) that it is going through the whole file and looking for .’s and anything after cause I kept doing .* as the pattern. Thanks for anyhelp you can give.

  • 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-06-15T00:36:29+00:00Added an answer on June 15, 2026 at 12:36 am

    shift shifts the positional parameters, so after calling shift the second parameter ($2) is now the first ($1). The second shift is not necessary, because you are done accessing the parameters. You need to either remove the shift

    #!/bin/sh
    fileExtension="$1"
    oldName="$2"
    newName=${oldName%%.*}${fileExtension}
    echo $newName
    

    or change $2 to $1.

    #!/bin/sh
    fileExtension="$1"
    shift
    oldName="$1"
    newName=${oldName%%.*}${fileExtension}
    echo $newName
    

    However, you are still missing a dot from your new file name. That is left as an exercise for the reader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm taking an intro class on database management systems, and had a question that
I have some C# class libraries, that were designed without taking into account things
I need a robust method that would combine multiple CSV files, taking into account
I've written a class as follows. I've written it taking into consideration that its
I am taking an intro to programming online. However, I am stuck on one
I am a college student taking a intro to programming C#. That being said,
I'm taking a unix/linux class and we have yet to learn variables or functions.
A college freshman I know taking an intro to computer science class asked me
Alright here's the deal, I'm taking an intro to C++ class at my university
I need to set a date that would be 30 days from now taking

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.