0

I'm trying to move some files using a bash script on a mac during recovery mode. I can successfully move the files by manually entering the command in Terminal after booting into recovery. However, one goal is to document the process and make it portable, so a script is desired. When I try to run the mv command from the script, I get the error No such file or directory. I've confirmed that the command executes correctly when I manually enter the filepaths, but the script continues to error.

I've tried using double-quotes(") and dollar signs ($), dollar signs ($) and braces ({}), and a few other combinations for variable evaluation. They all fail with the same error. I've also tried using a trailing slash on the src, globbing (*) on the src, and trailing slash on both the src and dest. I'm totally stumped. It could be that this is specific to MacOS recovery mode, but surely since the prompt announces -bash-3.2, this must be a bash 3.2 shell?

Please help - even our senior devs are stumped on this one...
Could it have anything to do with an improper parsing? I note that there is a /* on the end of the destination, and I didn't specify that...

Script is:

#! /bin/bash
#_# Setup
echo 'Setting up variables'
SYSDIR='/Volumes/Macintosh\ HD/System'
EXTDIR='Library/Extensions'
USERDIR='/Volumes/Macintosh\ HD/Users/admin'

#_# Bluetooth
echo 'Mitigating Bluetooth'
BLUE='IOBluetoothFamily.kext'
mkdir -p "$USERDIR/delete_me/$BLUE"
mv "$SYSDIR/$EXTDIR/$BLUE"/* "$USERDIR/delete_me/$BLUE"

echo '*Verify:* System Preferences/Bluetooth should display an error indicating bluetooth is not available.'

Output is:

-bash-3.2# ./bluetooth.sh 
Setting up variables
Mitigating Bluetooth
mv: rename /Volumes/Macintosh\ HD/System/Library/Extensions/IOBluetoothFamily.kext/* to /Volumes/Macintosh\ HD/Users/admin/delete_me/IOBluetoothFamily.kext/*: No such file or directory
*Verify:* System Preferences/Bluetooth should display an error indicating bluetooth is not available.
-bash-3.2# 
0

1 Answer 1

5

Your variables are quoted, you don't need to escape the spaces:

SYSDIR='/Volumes/Macintosh HD/System/'

(etc.)

Also (tangentially) related:

3
  • Thanks, I've taken your suggestions and updated the script; the same error still persists. I'll update the script in the question... Sep 26, 2019 at 18:09
  • 1
    @user3.1415927 You are still escaping the spaces. You don't need to. This is the actual error. The / at the end of directory paths is not an actual error, only unnecessary.
    – Kusalananda
    Sep 26, 2019 at 18:14
  • OMG you're a genius. Thanks. I mis-read your you don't need to escape the spaces as relating to the [curly] braces, not the backslash in the variable setting. Sep 26, 2019 at 18:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .