I am trying to take a filename from the ~/Pictures folder and supply it as an argument for the nomacs command. The filename contains some spaces, so I am using Bash substitution to escape spaces (I also want to take last file in the folder).
The code:
names=$(\ls ~/Pictures * | tac)
SAVEIFS=$IFS
IFS=$'\n'
names=($names)
IFS=$SAVEIFS
screenshot=~/Pictures/${names[0]}
screenshot=${screenshot// /\\ }
nomacs $screenshot
Example of the filename: Screenshot from 2017-09-13 18-05-42.png
The problem is that nomacs $screenshot does not work but when I execute nomacs Screenshot\ from\ 2017-09-13 18-05-42.png, it works as expected.
Should I use some special Bash technique for escaping spaces?