I need an interactive bash script template to copy files to predefined destination folders. If possible, when prompted for user input tab completion would be enabled for a predefined source directory. The basic logic would go something like this:
script example 1:
/bin/bash enable tab completion to load from /src/dir #perhaps using pwd as script is loaded echo "filename or pattern?" #interactively ask user to provide filename or pattern 'user input'=$FILENAME #define interactive user input as filename rsync -rv /src/dir/$FILENAME /dest/dir/ && rm -r /src/dir/$FILENAME done
I know it's rough/incorrect but hopefully the desired outcome is clear enough. Thanks in advance for any guidance!! Links to specific bash scripting techniques would be much appreciated.
#!/bin/bash read -e -p "Filename or pattern? " SRC_FILE rsync "$SRC_FILE" /dest/dir && rm -r "$SRC_FILE"
So, tab completion works great, and after "quoting" the strings
rsync stopped throwing errors. Looks like I now have a great little script doing EXACTLY what I need it to!! And I learned how to format code correctly on here, Thanks!!