Unix的击alias命令 [英] Unix Bash Alias Command
问题描述
我试图简化别名的帮助下我的工作命令在我的bash shell。
I am trying to simplify my work with the help of Alias commands in my bash shell.
问题陈述:
我想不同的文件从不同目录复制到一个单独的文件夹中。我使用这里的语法如下
Problem Statement: I want to copy different files from different directories to one single folder. The syntax i am using here is as below
cp <folder>/<file> <path>/file.dir
在这里我要保存filename.directory,便于识别目标文件。为了达到同样的,我已经写了下面的别名。
Here I want to save the destination file with filename.directory for easy identification. To achieve the same, I have written the below alias.
别名脚本
cp $Folder/$fileName ~/<path>/$fileName.$Folder
或
cp $1/$2 ~/<path>/$2.$1
期望的输出,
-
CP斌/文件1〜/桌面/个人/ file1.bin
-
CP等/文件2〜/桌面/个人/ file2.etc *
cp bin/file1 ~/Desktop/personal/file1.bin
cp etc/file2 ~/Desktop/personal/file2.etc*
然而,它未能在解析源文件。即 $文件夹
不替换我的第一个参数。
However, It's failing at parsing the source file. i.e. $Folder
is not replaced with my first argument.
cp: cannot stat `/file1': No such file or directory
我写上面的脚本不仅可以减少我的命令长度。由于我没有在上面code专家,寻求解决问题的专家的帮助。
I am writing the above script only to reduce my command lengths. As I am not expert in the above code, seeking any expert help in resolving the issue.
推荐答案
而不是使用别名,你可以使用你在一些合适的位置定义一个函数,如.profile或.bashrc中
Rather than using an alias you could use a function which you define in some suitable location such as .profile or .bashrc
例如:
mycp()
{
folder=$1
filename=$2
if [ $# -ne 2 ]
then
echo "Two parameters not entered"
return
fi
if [ -d $folder -a -r $folder/$filename ]
then
cp $folder/$filename ~/playpen/$filename.$folder
else
echo "Invalid parameter"
fi
}
这篇关于Unix的击alias命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!