I have a scenario where I have a script that monitors a file location and that file location has files copied to it, i.e. /home/matt/thefile.
I want an alias that if I do place myfile.txt it will overwrite /home/matt/thefile with myfile.txt.
A function would be more appropriate.
In Bourne-like shells:
place() { cp -- "$1" /home/matt/thefile; } In shells other than bash, yash and posh you can simplify it to:
place() cp -- "$1" /home/matt/thefile In fish:
function place cp -- $argv[1] /home/matt/thefile end in rc/es:
fn place { cp -- $1 /home/matt/the/file } It's in (t)csh that you'd need to use an alias as those shells don't have functions (it's also csh that introduced aliases in the first place). In (t)csh you can use history substitution to allow some kind of argument passing to aliases.
alias place 'cp -- \!:1 /home/matt/the/file' When called as place myfile.txt, they would copy myfile.txt to ~/thefile
If you wanted something that works regardless of the shell of the user, rather than having them add a shell-specific function/alias to their shell customization file, you'd create a script which you'd add in a directory that is in their command search path. Something like:
#! /bin/sh - exec cp -- "${1?Please give the file to copy as argument}" /home/matt/thefile
thefilebe overwritten or the content ofmyfile.txtattached to its end?