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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:38:13+00:00 2026-05-29T04:38:13+00:00

In bash I would like to get filename from a command line string. But

  • 0

In bash I would like to get filename from a command line string. But not the current ($0) script!

I have a file full of scripts with parameters. I need just the scripts from it!

For example i have a string like:
/path/to/file parameter1 -p2

i would like to get: /path/to/file (without the parameters)
even in cases:

/an\ example/with.dot.in_it/.hidden_file.sh par\ ameter1 p.dot.2
./script.sh p1 p2
../script.sh p1 p2
/any////relative/../path/./to/script.sh p1 p2

So in any valid linux path and filename cases!

Is there a regex for this purpose, or is there any other way to get this?

Thanks in advance!

  • 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-29T04:38:14+00:00Added an answer on May 29, 2026 at 4:38 am

    You can use perl’s command line regex feature combined with readlink command to always get full path to your script. Let’s data is your file name with all the command and their parameters. You can use script like this to get full path of your scripts:

    while read -r F
    do
        SCRIPT=$(perl -pe 's/^(.*?)(?<!\\) .*$/\1/;s/\\//g' <<< $F)
        readlink -f "$SCRIPT"
    done < data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to call a Python script from within a Bash while loop.
I have a Bash shell script in which I would like to pause execution
I would like to have a shell script that copies some logs from a
I would like a command line function that I can run on any file
I would like to extract some lines from a text file, I have started
From my bash shell I would like to call a program n times with
I would like to have Ctrl-l for clear in my Bash. How can you
I would like to change the target of symbolic link from within a bash
I am learning bash. I would like to do a simple script that, when
I need to write a bash script , and would like it to parse

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.