Please forgive me if this is too stupid a question as I am fairly new to scripting.
I have an alias in my .profile (ksh) like this:
The idea is to find all files in current dir and all subdir with the name specified in the param passed. So, I issue the command:
and it finds all the files beginning with x recursed through all the subdir. If I issue the command:
then it list all files with detailed file information. However if I change the alias like this:
and then issue the command ff x*, I get the following error:
I am just wondering why the same option works fine from the command line but not when added to the alias definition in .profile.
Thanks for the help.
Subhash.
Last edited by Franklin52; 04-16-2013 at 10:52 AM..
Reason: Please use code tags
An alias does not use command line parameters. It is replaced by its definition, and then the rest of your command line is expanded and appended to it. $1 in your case is not the second word on the command line but the first positional parameter of your interactive shell.
To enable passing of parameters, use a shell function.
So, if I understand correctly, the $1 in this case does nothing. When I issue the command "ff x*", it is expanded as "find . $1 x*" where the system looks for any files that have a name "$1" or starts with x.
Function is more usable as alias.
Where to put own function ?
Example make file $HOME/myfunc and then add line
to $HOME/.profile
After that you can use function as command with arguments
Test it
If you like to use ff also in subprocess, then set ENV variable in .profile
After this ENV setting ksh will execute myfunc always when you start ksh process => all function in myfunc is usable in subprocess.
Other method is use FPATH, but I like more "one file library" method. FPATH every function is in own file and filename is same as function name.
Of course every script, also .profile can include function. But if you like function working like alias = global then you need to set ENV and make some file which have to read every time when you start sh process. Usually it has named .kshrc. In my solution I have only show that name can be any. "Standard" is to use .shrc or .kshrc. Bash use .bashrc.
If you like function is usable also in child process then add to the .profile:
And make file .kshrc which include ex. those function which you like to be global.
But if you like to put together this need with ksh and bash, then make $HOME/.bashrc
and set ENV=$HOME/.bashrc + export in the profile.
=> function and all other settings are global in the bash and ksh93.
FPATH and autoload is the other method to make function working also in child process. = Autoload function when shell is launched.
I have not seen any command to set function to be global. Compare export for the variables.
Hi Guru's,
I am creating alias for db instance running on a server through script, am able to create them based on /etc/oratab entries and can use successfully with the below script.
#!/bin/bash
SCRIPT_PATH=${HOME}/scripts/db/script... (3 Replies)
hi,
we have eth1; in the beginning it was proposed to create from eth1, eth1.2500 and eth1.240. It did not worked cause vlan 1.2500 was not tagged in the switch.
so they decided to leave eth1 like a physical interface with eth1.2500 config (removel vlan tag) and create eth1.240
but it did... (0 Replies)
If one:
$ find -name 'some expression' -type f > newfile
and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory.
I am... (3 Replies)
Hi to all,
I'm facing some problems when adding an alias like:
#alias list="ls -al | awk '{ print $1, $2, $3, $4, (($5/1048576))"\t", $6, $7, $8, $9 }'"
and when I enter:
#list
I get:
Syntax Error The source line is 1.
The error context is
{ print >>> , <<<
awk:... (3 Replies)
Hi all, well i am configuring backuppc for awhile, anyway my current problem is, i set a smarthost, configured the mail to use our ISP smtp server, and its working successfully thanks to ALLAH, now i want to set an alias for mails( it was working when it was using the local smtp server), so the... (0 Replies)
Hi folks,
I'm trying to define the following command as alias in .cshrc file:
ls -ltr | grep ^d | awk '{print $9}' | xargs du -hs
I defined it as the following:
alias nirdirs '`ls -ltr | grep "^d" | awk "{print \\$9}" | xargs du -hs`'
I've got the following error when I've run the alias:... (7 Replies)
Hi-
I am newish to the mac osx unix interface. I want to set up top so that it always displays the username. I can use this command to do this:
top -ocpu -P ' PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE USER' -p '$aaaa ^bbbbbbbbb $cccc $wwwwwww $ee... (1 Reply)
okay how do i make an alias that has a space in it?
for most of my other ones i've simply done within my ~/.bash_profile
alias `ls`='ls -laF'
but with
alias `sudo su`='sh hello.sh'
I'm unable to make it work
in addition i was wondering how i could allow the user to type in... (1 Reply)