Jump to content

BASH: When do you use separate or grouped - options?


Lost In Cyberia
 Share

Recommended Posts

Hey guys, another question. What determines the separation of tack options when using bash? For example in a few of the haktips, Darren separates his switches like

lsof -i -n -P

but in others he groups them together like:

aircrack -nG

Just examples, but yet, what causes you to be able to group them with just 1 minus sign, or separate them out? Or is it just a preference of the moment?

Cheers!

Link to comment
Share on other sites

Most standard *nix programs use the getopt library to parse the parameters on the command line. If they have used the getopt library then you will be able to merge any switch parameters (so "ls -l -t -o -r" can become "ls -ltor").

If you have a parameter that requires and argument you can't merge it into the middle of a merged group of switches as then it will think the rest of the switches are the argument, though you can merge it on the end of the group.

e.g.

  sed -er 's/:/\t/g' /etc/passwd

doesn't work, but

sed -re 's/:/\t/g' /etc/passwd

does.

Wethere you should merge switches or not, assuming there is no company policy you have to follow, really comes down to personal preference. When scripting just use whichever makes the script easiest to read (which may be to use long opts where available as they tend to be more descriptive).

Link to comment
Share on other sites

Most standard *nix programs use the getopt library to parse the parameters on the command line. If they have used the getopt library then you will be able to merge any switch parameters (so "ls -l -t -o -r" can become "ls -ltor").

If you have a parameter that requires and argument you can't merge it into the middle of a merged group of switches as then it will think the rest of the switches are the argument, though you can merge it on the end of the group.

e.g.

  sed -er 's/:/\t/g' /etc/passwd

doesn't work, but

sed -re 's/:/\t/g' /etc/passwd

does.

Wethere you should merge switches or not, assuming there is no company policy you have to follow, really comes down to personal preference. When scripting just use whichever makes the script easiest to read (which may be to use long opts where available as they tend to be more descriptive).

Thanks! Makes sense!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...