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

  • SEARCH
  • Home
  • 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 8479611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:04:49+00:00 2026-06-10T19:04:49+00:00

please pardon since I am a UNIX beginner. I wanna write a shell script

  • 0

please pardon since I am a UNIX beginner.

I wanna write a shell script that can ask user type in the filename and output the number of lines in that file, here is my code:

echo "Pls enter your filename:"
read filename
result=wc -l $filename

echo "Your file has $result lines"

However, I couldn’t get it working since it complains about the identifier “filename”. Could experts help?Thanks !!

  • 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-10T19:04:50+00:00Added an answer on June 10, 2026 at 7:04 pm

    That works fine, at least in bash. Well, the read works fine. However, the assignment to result should probably be:

    result=$(wc -l $filename)
    

    but, since that command outputs both the line count and the filename, you might want to change it a little to just get the line count, something like:

    result=$(cat $filename | wc -l)
    

    or:

    result=$(wc -l <$filename)
    

    The command you have:

    result=wc -l $filename
    

    will set result to the literal wc, then try to execute the -l command.

    For example, the following five-line script:

    #!/bin/bash
    echo "Pls enter your filename:"
    read filename
    result=$(cat $filename | wc -l)
    echo "Your file has $result lines"
    

    will, when run and given its name as input, produce the following:

    Your file has 5 lines
    

    If you’re not using bash, you need to specify which shell you are using. Different shells have different ways of doing things.

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

Sidebar

Related Questions

I am an iOS newbie, so please pardon me if this is a beginner
Please pardon my lack of Photoshop skills, but I'm curious what type of strategy
I'm still learning CSS, so please pardon me if this is something that is
Disclaimer, Please pardon grammatical syntax. I'm using the simple linkedin php library that is
I'm completely new to Simple Build Tool, so please pardon my beginner question. I'm
Please pardon my ignorance. I'm looking for a point in the right direction. I
Warning - I'm a front end designer; Please pardon my fumbling of the PHP
Perhaps this is a very basic question, please pardon me if it is ---
For anybody who has seen / used Magento, can you please tell me where
Please pardon me if this has been asked before, but I'm wondering if there

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.