Home > database >  zsh wrapper: how to add prefix to the shell command parameters?
zsh wrapper: how to add prefix to the shell command parameters?

Time:11-19

For example, I have defined a zsh-script called "myCmd.sh" when I run

myCmd --op1 "/p1/p2" --op2 "/p3/p4" -op3 "a"

it should actually call

Cmd --op1 "/mnt/d/p1/p2" --op2 "/mnt/d/p3/p4" -op3 "a"

In other words, once a path string occurred in the command parameters, the prefix "/mnt/d" will be added, the cmd and other args or parameters will remain the same.

CodePudding user response:

You can use static named directories to have filename expansion produce the desired path, saving you a little typing. For example,

d=/mnt/d

cmd --opt1 ~d/p1/p2 --op2 ~d/p3/p4

is the same as

cmd --opt1 /mnt/d/p1/p2 --op2 /mnt/d/p3/p4

~name, where name is any parameter with a value that starts with /, is expanded to the value of the parameter.

An example:

% echo ~d
zsh: no such user or named directory
% d=/mnt/d
% echo ~d
/mnt/d
  • Related