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
thefile
be overwritten or the content ofmyfile.txt
attached to its end? – dessert Sep 18 '17 at 19:10