Deleting a file from User Library

New Contributor

I put this together and all of it's pieces work fine when run in terminal. I just cannot get it to work when running it in JAMF. The $user seems to be the issue. When I add the user directory of the test Mac it works fine but without it I get a "No such file or directory" error. Can anyone see what I am doing wrong? The macOS is Monterey 12.1 if that helps

# Pull current logged in user into 'user' variable.
user=`ls -l /dev/console | cut -d " " -f 4`

# Delete User CCDA default preferences
rm -R '/Users/$user/Library/Application Support/Adobe/OOBE/com.adobe.acc.container.default.prefs'

Any help would be appreciated.


Contributor II

Two things:

There are edge cases where your code for detecting the logged-in user will not properly report the user. Use instead:

user=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )


Second, you are using single quotes in your rm statement, which in shell is literal characters. Change to double-quotes and it should work.