Score:0

Bash command with argument stream

in flag

I look for a manner to provide a bash command with multiple arguments only by some syntax sugar. I already know $@ and $*, but I do not know how to use them properly. It would be nice with the following syntax:

define args
command &args

A further syntax can be as follows:

  1. Concatenate single and stream arguments in a row
define args_stream
command &args_stream arg_1
  1. Concatenate single and stream alternatively
define args_stream1
define args_stream2
command &args_stream arg_1 &args_stream2

It seems kind of a bad practice, but I wish to reduce some rows of my shell scripts... :(

Update Examples: Since the question is so broad that the readers could not grasp its actual meaning, I provide examples:

  1. My printHeader function has 7 arguments, but most of them may be parametrized. One option is to set my variable to some default parameter. However, I would have to order the arguments in an unusual form, for main arguments as the most right elements. Other form is to write the arguments as I mention: I would like to right these arguments, stream or array, as I mention as below:
command $1 [$2.1 $2.2 $2.3] $3 
  1. By run of command git --help, I receive the log below:

usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

Arguments between brackets are optional, but may be provided by double hyphen -- notation. It is an option for my argument stream notation.

David avatar
cn flag
As I read your question I see nothing that has anything to do with Ubuntu.
cn flag
Ray
Personally, I think you're going about it wrong. You've decided on `bash` and are asking how one would do what you suggested with `bash`. Using your point #2 with `git` as an example, I don't consider myself an expert in `bash`, but if I had to do that, I definitely wouldn't use `bash`. If `git` were a C++ program, I'd use Boost's [program options](https://www.boost.org/doc/libs/1_62_0/doc/html/program_options.html). I'm not saying you can't do it with `bash`, but I don't expect it to be easy.
Score:1
lc flag

Maybe you're talking about $1, $2, and so on, into a script where you can let's just say, youtube-dl argument1 argument2.

$ command argument1 argument2

Where $1 and $2 represent those arguments.

Or,

There are also other ways to do it so:

command="proot"
command+=" --link2symlink"
command+=" -0"
command+=" -r $folder"

As examples.

Since the question is still unclear to me, let me know before for edit or deleting this answer appropriately.

Bruno Henrique Peixoto avatar
in flag
In case one want to write args [$1 $2] like in python language instead of separated $1 $2
Satoshi Nakamoto avatar
lc flag
not really because in my example is a bash script
Bruno Henrique Peixoto avatar
in flag
But is it possible or may I have to encapsulate it in some other function?
Satoshi Nakamoto avatar
lc flag
your question is very confuse and not specific, that happens when we don't understand well a topic. I'm sure your problem is real but needs clear direction
Bruno Henrique Peixoto avatar
in flag
It seems my case may be solved by xargs. But I appreciate the effort to solve my issue. :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.