简体   繁体   中英

linux alias with part of path

Lately I have been getting familiar with aliases in the linux shell. I find them particularly useful for replacing hdfs dfs commands like this:

alias hls="hdfs dfs -ls"

This alias can be used like

hls /my/directory/ 

which will list the contents in that folder on the hadoop file system.

I would like to add another hdfs dfs -ls alias that contains a root directory, something along the lines of:

alias hlsr="hdfs dfs -ls /my/root/directory/"

I would then want to use this command as follows:

hlsr rest/of/path

which would then result in listing the contents of the path /my/root/directory/rest/of/path.

The problem is combining the alias, that ends with a root path, with a string which represents the rest of that path.

Does anyone know how to do this? Would I have to write a function or could it be done with aliases as well?

Thanks, J

You can use a function in a file to be sourced. Let's call a file with name myfunctions.sh

hls () 
{ 
    hdfs dfs -ls "$1";
}

The argument $1 is your first parameter and then you have to source the file with source myfunctions.sh or . myfunctions.sh . myfunctions.sh .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM