1

I have a simple bash script that tries to find a folder, and if it can't find it, it gives an error. It gets a argument and tries to find a folder in the .local folder called menu. I have the folder, but it can't find it:

Permissions Links Size User Group Date Modified Name
drwxrwxrwx@     1    - lost lost  15 Jul 22:19   menu

My code:

if [[ $1 == "edit" ]]
then
  if [[ $2 == "" ]]
  then
    echo "Error: You need to enter a playlist name."
    exit
  fi
  if [[ -e "~/.local/share/folder/$2/" ]]
  then
    $EDITOR ~/.local/share/folder/$2
  else
    echo "Error: No playlist called $2 exists."
  fi
fi

I'm running it with the argument edit menu. Output: Error: No playlist called menu exists.

Does anyone know what is wrong with this code?

Thanks.

This doesn't work using -f or -d too.

zoldxk
  • 2,632
  • 1
  • 7
  • 29
fg_
  • 59
  • 1
  • 8
  • 2
    Please add a valid shebang (`#!/bin/bash`) to your script, then paste it at http://www.shellcheck.net/ and try to implement all the recommendations made there. – Cyrus Jul 16 '23 at 01:41
  • 2
    The tilde `(~)` expansion doesn't work inside quotes or when enclosed in double quotes, try giving the full path – zoldxk Jul 16 '23 at 01:44
  • 1
    See ["Tilde in path doesn't expand to home directory"](https://stackoverflow.com/questions/5748216/tilde-in-path-doesnt-expand-to-home-directory). In this situation, you could use either `[[ -e ~/".local/share/folder/$2/" ]]` or `[[ -e "$HOME/.local/share/folder/$2/" ]]`. – Gordon Davisson Jul 16 '23 at 01:55

0 Answers0