When entered directory into the command line, this:
ls -d -1 "/Volumes/Development/My Project/Project"/**/* | grep \.png$
Prints a list of all the file ending in .png
.
However when I try and create a script:
#! /bin/bash
clear ;
# Tempoary dir for processing
mkdir /tmp/ScriptOutput/ ;
wdir="/Volumes/Development/My Project/Project" ;
echo "Working Dir: $wdir" ;
# Get every .PNG file in the project
for image in `ls -d -1 "$wdir"/**/* | grep \.png$`; do
...
done
I get the error:
cp: /Volumes/Development/My: No such file or directory
The space is causing an issue, but I don't know why?
Filename with Spaces in Bash A simple method will be to rename the file that you are trying to access and remove spaces. Some other methods are using single or double quotations on the file name with spaces or using escape (\) symbol right before the space.
Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.
To see a list of all subdirectories and files within your current working directory, use the command ls . In the example above, ls printed the contents of the home directory which contains the subdirectories called documents and downloads and the files called addresses.
In the Linux operating system, we can run commands by passing multiple arguments. A space separates each argument. So, if we give the path that has a space, it will be considered two different arguments instead of one a single path.
If you fine with using while read
and subprocess created by pipe, you can:
find . -name '*.png' | while read FILE
do
echo "the File is [$FILE]"
done
Use more quotes and don't parse ls
output.
for image in "$wdir"/**/*.png; do
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With