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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:53:38+00:00 2026-06-01T07:53:38+00:00

I have a path that I retrieve with the pwd command, I have to

  • 0

I have a path that I retrieve with the pwd command, I have to modify that path runtime in my shell script. For istance let’s say I have /var/www/cgi-script, I have to modify it in /var/www/etc. What I am trying to do is retrieve the last index of “/”, take a substring and then add etc. I tryed with awk several times but I can’t seem to find a solution. Is there a way to use a reverse index?

path=`pwd`;
char="/"
pathindex=`awk -v a="$path" -v b="$char" 'BEGIN { print index(a,b)}'`
  • 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-01T07:53:39+00:00Added an answer on June 1, 2026 at 7:53 am

    Check out dirname:

    $ pwd
    /var/www/cgi-script
    $ echo $PWD
    /var/www/cgi-script
    $ echo `dirname $PWD`/etc
    /var/www/etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .sh unix shell script that receives as a parameter a path,
I have a path + filename that contains [] several times. What i want
We have an application that needs to know the path that it is executed
I have a variable in code that can have file path or url as
I have for example .pdf file (path to that file). How to open this
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
In my live site I have php include() and require() that have full path
Using windows server, I have a path to a file that, when you click
I have a virtual path (example: ~/Images/Banner.jpg) and I want to make that an
It's not that I can't google for myself, however others have tread this path

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.