I am trying to create a bash alias to do the following:
- create a folder (with the current date as the folder name)
- move (or copy, either is fine with me) a file from the current folder into the new folder.
The filename is passed to the alias as a variable. E.g., my-alias file.txt
Here are a few of the ways I've tried to go about it (although I've tried quite a few more variations):
alias my-alias="mkdir -v -p '$(date +%F)-List' && cp $1 './$(date +%F)-List/$1' && cd '$(date +%F)-List'"
alias my-alias="mkdir -v -p '$(date +%F)-List' && cp $1 ./$(date +%F)-List/$1 && cd '$(date +%F)-List'"
alias my-alias="mkdir -v -p '$(date +%F)-List' && cd '$(date +%F)-List' && cp ../$1 ./$1"
I've tried many ways of writing the command, and none work.
What am I over looking?
This is on Mac OS which should be the same as most other Linux environments.
UPDATE: WHERE I WENT WRONG
I've realised where I was getting confused. I have a lot of aliases set up that "appear" to receive arguments. I set them up a long time ago (some years ago). I now realise that the aliases only seem to receive the arguments because an alias can process whatever follows it when entered on command line. But it will only process those "arguments" if they are at the end of the command string the alias refers to, and in the same order. So once I started trying to shuffle the arguments around in my aliases command string, the alias would break. So yes, the best approach is to use a function.