Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"basename" used in subshell returns "command not found" [duplicate]

Tags:

bash

subshell

When running this script:

#!/bin/sh -ex

if [[ $# -ne 1 ]]; then
  echo "./import-public-ssh-key.sh <absolute path to public key>"
  exit 1;
fi

PATH=$1
KEY=$(basename ${PATH})

I get:

./import-public-ssh-key.sh: line 9: basename: command not found

without the subshell basename works:

$ basename /Users/mles/.ssh/id_rsa.pub
id_rsa.pub

Why is basename not working in the subshell? I'm on a mac if this is relevant.

like image 752
mles Avatar asked Dec 29 '18 16:12

mles


1 Answers

You reset the PATH. Don't do that. The shell searches all the directories listed in PATH, and you have changed it so that PATH no longer contains the directory that contains basename.

like image 91
William Pursell Avatar answered Sep 28 '22 18:09

William Pursell