I am learning shell scripting, and I have written two scripts one that copies many files at once to a folder and if the folder does not exist it creates it, works like a charm! You may use it :D and the other one that moves them, I mean cuts and pastes :)
to copy:
#!/bin/bash if [ ! -e "$2" ] then mkdir $2 fi if [ "$3" ]; then cp -rn $1/*.$3 $2 echo "Copying *.$3 done!" else cp -rn $1/*.* $2 echo 'Copying done!' fi to move:
#!/bin/bash if [ ! -e "$2" ] then mkdir $2 fi if [ $3 ]; then mv -i $1/*.$3 $2 echo "Moving *.$3 done!" else mv -i $1/*.* $2 echo 'Moving done!' fi I would like to be able to use them like any other shell command (eg. ls, ping, cd...) everywhere in my system. How can I achieve that? Thanks!
$PATHenvironment variable.[ $3 ]should be[ "$3" ]. Similarly,mv -i $1/*.$3 $2should bemv -i "$1"/*."$3" "$2"-- if you don't quote your expansions they're subject to word-splitting, so filenames or directories with spaces will misbehave badly. shellcheck.net will detect these issues automatically.