0

My bash skills need fine-tuning.

If I comment out line B (i.e. so I have a full path defined), the script runs fine. If I uncomment line B (i.e. I build the path up) I get an error. Why?

Here's the script (used to run Apple's instruments tool):

#!/bin/bash

DEVICE="foo"
TEST="bar"
APP="etc"

PATH="/Users/snowcrash"

SCRIPT="/Users/snowcrash/scriptA.js"  # Line A runs fine
SCRIPT="$PATH/scriptA.js" # Line B gives me 'instruments: command not found'

instruments -w "$DEVICE" -t "$TEST" "$APP" -e UIASCRIPT "$SCRIPT"
Snowcrash
  • 80,579
  • 89
  • 266
  • 376
  • 5
    Don't use PATH. Don't know if that's the cause of your error, but PATH is the list of directories that the shell looks for executables. – racraman Mar 06 '15 at 23:02
  • doh! yes, that was the problem. – Snowcrash Mar 06 '15 at 23:08
  • Are you sure? I just tested it with GNU bash, version 4.1.5(1), and my local variable could always override the exported one, even if it was called `PATH`. – Michael Jaros Mar 06 '15 at 23:11
  • 2
    @MichaelJaros, changing the local variable will always immediately and automatically change the environment variable it came from. – Charles Duffy Mar 06 '15 at 23:13
  • 1
    @SnowCrash, btw, the best-practices way to avoid this is to use at least partially lowercase (if not all-lowercase) names for shell variables that are neither environment variables or builtins (the two category for which all-caps names are reserved). – Charles Duffy Mar 06 '15 at 23:14
  • @CharlesDuffy That information is consistent with my test, thus reinforcing my doubts that using the `PATH` variable caused that problem in above code snippet as @Snow Crash stated in comment #2. – Michael Jaros Mar 06 '15 at 23:18
  • 1
    @MichaelJaros, pardon? That setting the local variable PATH also updates the environment variable PATH is _entirely_ consistent with `instruments: command not found`, assuming that `instruments` isn't in `/Users/snowcrash`. – Charles Duffy Mar 06 '15 at 23:21
  • @racraman: You should post that as an answer. – Keith Thompson Mar 07 '15 at 00:06
  • @CharlesDuffy Er, yes :) It's late here. – Michael Jaros Mar 07 '15 at 00:37

0 Answers0