I am having a specific issue when trying to execute the docker run command on an image I have created.
I have ran the spellchecker for my scrip and know I can improve the style by using double quotes- but frankly this does not effect my script from running so please refrain for commenting on this at the moment.
See the full scrip below
#!/bin/bash
echo File Finder
echo what directory would you like to find?
read -r User
echo $User
COMMAND_DIRECTORY="/c/Users/HansPeterJonasHogh-J/dev/repos/${User}"
echo $COMMAND_DIRECTORY
if [ -d $COMMAND_DIRECTORY ]
then
echo "The $COMMAND_DIRECTORY exists"
cd $COMMAND_DIRECTORY
ls
echo "This is the number of files you have"
# list all files and count
ls -1 | wc -l
#function to loop through all files and copy into folder
ls -lx
echo "What type of file you want sorted "
read FILE_EXT
echo $FILE_EXT
echo "What name would you like the folder called"
read USER_FOLDER
ECHO $USER_FOLDER
for file in $COMMAND_DIRECTORY/*
do
if [[ "$file" == *$FILE_EXT ]]
then
mkdir -p ${USER_FOLDER}
mv $file ${USER_FOLDER}
fi
done;
#echo what file you want to search for
#function loop through folder and find file
else
echo "The $COMMAND_DIRECTORY does not exist"
fi
The terminal output is this:
$ docker run filefind
File Finder
what directory would you like to find?
/c/Users/XYZ/dev/repos/
': not a valid identifierd: `User
file-find.sh: line 27: syntax error near unexpected token `$'do\r''
'ile-find.sh: line 27: ` do
Previously I have copied everything into notepad++, edit, EOL conversion and selected Unix which has worked fine (my understanding this has something to do with docker and windows not being inherently compatible).
In the past I have parsed arguments in the terminal while executing the docker run command- however, this time round I want the user to be asked the questions first before they type hence the necessity for Read.
I hope this makes sense- and would love to get the answer but explanation as-well.
You need to run docker in “interactive mode”:
docker run -it filefind
Otherwise, the stdin of you script (inside the container) is connected to /dev/null instead of your terminal.