LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Possible to set "-h" for all programs? (https://www.linuxquestions.org/questions/linux-newbie-8/possible-to-set-h-for-all-programs-803183/)

gaikokujinkyofusho 04-20-2010 10:05 PM

Possible to set "-h" for all programs?
 
Hi, i was busy setting up aliases for all the different commands that i use that have the -h (human readable format, or something like that) and it occurred to me that maybe, possibly (though i don't know how) it might be possible to set that parameter "universally" or at least for the applications where it can be used. So my question is, is that possible and if so how can it be done? Any help/ideas would be greatly appreciated!

Cheers,

-Gaikio

grail 04-20-2010 10:48 PM

I could be wrong but to the best of my knowledge your current option of creating aliases is the way to go.
However, I presume you are simply writing an alias for each command?
You may be better suited, as i am imagining there are a few you would like to set, to use a loop
based on an array of your commands, see below link on reference for how to use arrays in bash.
The general idea would be:

Code:

comm_array=(ls df) # add as many as required here

for command in ${comm_array[@]}
do
    alias $command="$command -h"
done


Reference: http://tldp.org/LDP/abs/html/arrays.html

chrism01 04-21-2010 01:14 AM

I'm afraid that grail's approach is your best bet. The programs are all written by different people (see the bottom of each man page) and there's no enforced std for options...

gaikokujinkyofusho 04-21-2010 11:44 AM

Hi Grail, sorry for the belated reply. I tried your idea and it worked like a charm! Thanks!

onebuck 04-21-2010 12:40 PM

Hi,

Just a few useful links;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Bash Reference Manual <<< Look here
Advanced Bash-Scripting Guide <<< and here
Linux Newbie Admin Guide
LinuxSelfHelp
Getting Started with Linux

The above links and others can be found at 'Slackware-Links' . More than just SlackwareŽ links!

grail 04-21-2010 10:43 PM

Cool. Please mark as SOLVED ;)

salasi 04-22-2010 06:25 PM

one (or two) possible disadvantages with the Grail solution is
  • if you type 'du -h', you will actually pass 'du -h -h' to the command. I tried a couple of cases, and it looks as if the '-h -h' output is always the same as the '-h' output. I can't believe that this behaviour is one that is tested for, so you might want to check with every util for which you will use it, if this is of concern to you (maybe you are absolutely sure that this will never happen)
  • if you should decide that you don't in some particular case want the 'human readable output format' (maybe you are feeling particularly machine-like that day) there isn't a particularly easy way of turning it off (ok, there is a pretty easy way, once you've thought about it)
Provided that you are happy living with the limitations, it seems like a good solution.

chrism01 04-22-2010 06:27 PM

If I need an an alias, I always (usually?) provide new name so it won't interfere with normal operations.

syg00 04-22-2010 06:42 PM

I go the other way - if I don't want the (same named) alias I use "\<command> ..."

Bratmon 04-22-2010 07:58 PM

Add -h to everything? Even something like shutdown?

grail 04-22-2010 09:44 PM

@Bratmon - no not everything, just those in the array. So unless he puts shutdown in there halt won't be the default :)


All times are GMT -5. The time now is 01:58 AM.