0

I need for user to point out a directory path in command line but when trying to suggest folders with tab it gives me tab spaces

function selectFolder() {
  local dir
  read -p "Enter the path of the dir : "  dir

  cd "$dir"  || {
    exit 0
  }
  local dir=$(pwd)
  cd - > /dev/null 2>&1
  echo "$dir"
}

Can't find a clue so far please help

New contributor
Bat Man is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • you need to add -e to read – bac0n Feb 14 at 18:47
  • 10x @bac0n appreciate it – Bat Man 2 days ago
0

Here's the answer of the working function for those who face the same problem

function selectFolder() {
  local dir
  read -ep "Enter the path of the dir : "  dir

  {
    cd "$dir"
  } || {
    exit 0
  }
  local dir=$(pwd)
  cd - > /dev/null 2>&1
  echo "$dir"
}

# invoke function
selectFolder
New contributor
Bat Man is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Bat Man is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.