Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1 votes
1 answer
61 views

Script is not activating the options

I'm making a script to open url by terminal and when typing: #!/usr/bin/bash ## origin: https://www.vivaolinux.com.br/script/Abrir-arquivos-em-nova-aba-no-Firefox ## ### Se quizer que o novo link ...
user avatar
0 votes
1 answer
761 views

Add options with default value on shell script

I want to add some options to my custom shell script. I can show it to you since it is not top secret content :-P In my experience, there are two option types, set and unset options: set options are ...
Bruno Peixoto's user avatar
3 votes
1 answer
5k views

in bash the option "set -e" causes exit immediately, which is a problem in sourced scripts

When using bash in a terminal often scripts have to be run sourced. In such cases terminating the script must be done by "return", but not by "exit" in order to not kill the basic ...
Anton Wessel's user avatar
0 votes
1 answer
508 views

getopt and case function not executing

I encountered such a problem when passing a parameter to a script, the function corresponding to the case menu is not executed. The script accepts parameters as input and performs the appropriate ...
Maverick's user avatar
1 vote
1 answer
10k views

What does the "+x" option in "bash +x script.sh" mean?

I know what bash -x does, but what does bash +x do? Googling found no results and the manual also says nothing about it.
user1206899's user avatar
1 vote
1 answer
1k views

Invoke a program in a Bash script with command line parameters stored in a variable

Is it possible to invoke some program in a Bash script with complete command line parameters (both the key and the value) stored in variables? I use the following scanimage call in a script: scanimage ...
Tobias Leupold's user avatar
1 vote
1 answer
2k views

How to get option value $OPTARG correctly?

I would like to get an option value when launching a shcell. I wrote: optstring=hcnxl: V=0 while getopts $optstring opt; do case $opt in h) V=1 ;; c) V=2 ;; n) V=3 ;; x) V=4 ;; ...
Gigiux's user avatar
  • 537
-1 votes
1 answer
48 views

Parsing `-C8` to get value to option -C

I want to parse -C8 to a bash function and get the numeric value in a variable. I have seen argument parsing implementations for -C 8 and -C=8, but not for -C8. while (( $# > 0 )); do case $1 ...
Vera's user avatar
  • 1
0 votes
2 answers
144 views

Exit while loop when reaching last positional argument

I want to adapt this so that when the function reaches the last positional argument, the while condition exits. console_codes () { local exec=0 local narg="$#" iarg=0 while (( narg > 0 ...
Vera's user avatar
  • 1
2 votes
1 answer
85 views

Dealing with simple help option far bash function

I have adapted some code I had to handle just a single possible option. Either run the function or use the help option to give a brief description. activate-jet () { local iarg=0 narg="$#&...
Vera's user avatar
  • 1
-1 votes
1 answer
73 views

Is it OK if I add a duplicated option when calling an alias for rm?

I have alias rm='rm -i' in .bashrc. Now, if I use rm -i by mistake, it will become rm -i -i. Would anything go wrong because of two same options?
Wade Wayne's user avatar
1 vote
2 answers
7k views

Can you make a bash script's option arguments be optional?

I would like either of these inputs to work. That is, the -n option itself is optional – I already know how to do that – but it then may have an optional parameter on top. If no parameter is given, a ...
WoodrowShigeru's user avatar
0 votes
1 answer
315 views

Setting verbosity level from list of function arguments

I am using a bash function to which I pass arguments. I would like to capture if a particular option was defined by the user -v NUM or --verbosity=NUM. If defined as described, I would like to set ...
Isabel's user avatar
  • 89
2 votes
4 answers
1k views

When are grouped parentheses for multiple options necessary?

I am using the find and grep commands. Getting quite confused about when multiple options are joined by "or" with the -o flag and the use of grouped parentheses, and when grouped parentheses ...
Pietru's user avatar
  • 393
0 votes
0 answers
98 views

Removing delimiters from bash array elements, then transferring result to another array

I am using an option variable array incl that stores filename extensions. ("--incl") local incl+=("$2") ; shift 2 ;; The function can then be called using --incl .texi --...
Pietru's user avatar
  • 393
0 votes
0 answers
148 views

Handling Optional Arguments in bash

I have the following function that is supposed to write strings in new lines. There is a warning option, so that when -w is set by the user, some lines get coloured in red. -w allows an optional ...
Pietru's user avatar
  • 393
1 vote
1 answer
2k views

options with optional values using getopt

I have the following function and would like to look into how options with optional values can be set up using getopt. Would like to have -w taking on default values region -w -- "Text" And ...
Pietru's user avatar
  • 393
1 vote
1 answer
525 views

Passing arguments to a command safely

It is well known that it's a bad idea to do something of the kind <command> $FILENAME, since you can have a file whose name is for example -<option> and then instead of executing <...
Carla is my name's user avatar
0 votes
1 answer
2k views

Bash script selecting folder

I am trying to list all the directory latest modified folder first using select, but I am stuck. Let's say I have: Folder1 ThisIsAnotherDir Directory New Directory This IS not_Same Directory When I ...
KpDean's user avatar
  • 3
0 votes
0 answers
870 views

Bash script that accepts options given after arguments in command line

I have a bash script that accepts a number of optional flags and two required arguments. Currently, if the command line call is ~/script.sh -a -b arg1 arg2 it works just fine, but if the call is ~/...
Josh's user avatar
  • 303
4 votes
1 answer
2k views

Bash Shell “noexec” Option Usage Purpose

-n noexec ; Read commands and check syntax but do not execute them. Can you give an example of when we will need "noexec" which is one of the Bash options? Can someone give me an example of ...
testter's user avatar
  • 1,470
0 votes
1 answer
59 views

aliasing command options

Is there any way to alias the options of a command? For instance, I often use the options -mindepth and -maxdepth with find, but these are quite long at 9 characters apiece, and don't have ...
user001's user avatar
  • 3,758
0 votes
2 answers
3k views

correct order while combining different options of a command

I usually combine options together whenever there are more than one option to be used with respect to some command. For example , if i want to create an archive using tar i will write tar -cvf archive....
LocalHost's user avatar
  • 529
1 vote
1 answer
3k views

How do I pass long-style command line options to a bash script using getopt?

I have this script that I have cobbled together from bits of lore I've gleaned from googling: #!/usr/bin/env bash usage() { declare -r script_name=$(basename "$0") echo """ Usage: "${...
braveterry's user avatar
2 votes
1 answer
91 views

su: What does the hyphen with nothing immediately following it mean?

Written as if it were an option, e.g: > su - someuser Don’t the space breaks apart “-“ and “someuser”? I went through the manpage but didn’t notice an entry for it.
Vita's user avatar
  • 311
0 votes
1 answer
348 views

Create custom parameters (options) for already existing commands?

Recently I 've been wanting to create a custom parameter for pacman. To elaborate, I have tweaked pacman.conf so that specific packages (linux, linux-firmware, and a couple more) are ignored when I ...
Spyros's user avatar
  • 1
7 votes
2 answers
472 views

Bash how does skip-completed-text work?

More concise version With "\t": menu-complete in ~/.inputrc create these two files, $ touch one.two.txt $ touch one.four.txt start writing the following, $ ls one hit Tab and you'll get $ ...
Enlico's user avatar
  • 1,747
2 votes
1 answer
25k views

how to properly parse shell script flags and arguments using getopts

I'm using this : for example ./imgSorter.sh -d directory -f format the scripts' content is : #!/bin/bash while getopts ":d:f:" opt; do case $opt in d) echo "-d was triggered with $...
St3an's user avatar
  • 123
0 votes
1 answer
112 views

passing options from an array to built in ls command in UNIX [closed]

I am writing a shell script that takes several args like -l -s -a -f thing ming and append only those starting with -. This is my code: arrayOfArgs=() for arg in "$@": do case arg in -*) ...
Samun's user avatar
  • 37
-1 votes
1 answer
1k views

How shall we understand "if no arguments remain after option processing"?

Basy manual says that for the command bash: -s If this option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option ...
Tim's user avatar
  • 105k
0 votes
3 answers
1k views

parsing a command option in a bash script

I wrote I ‘quick’ script, and then thought of adding a “—nomail” option that would shut off my mail switch (of which the syntax is piped in from echo). I thought this would be easy but I think, ...
SSDdude's user avatar
  • 171
0 votes
2 answers
1k views

How to pass every line of a file as options to a command?

I'd like to write a script that reads a file and passes every line as options (or "option arguments") to a command, like this: command -o "1st line" -o "2nd line" ... -o "last line" args What's the ...
jacek's user avatar
  • 21
19 votes
3 answers
4k views

Why do options in a quoted variable fail, but work when unquoted?

I read about that I should quote variables in bash, e.g. "$foo" instead of $foo. However, while writing a script, I found an a case where it works without quotes but not with them: wget_options='--...
z32a7ul's user avatar
  • 445
1 vote
1 answer
2k views

Bash get input while flag present?

I'm writing a bash script that has optional flags but also an input. I can't get the input as $1 because when flags are present the input is shifted. So for example if I run script.sh test then $1 ...
Philip Kirkbride's user avatar
1 vote
2 answers
529 views

autoconf tried to invoke "exec -m' under bash, but -m is not a legal operand for exec

This question may really be about where to get help, rather than help for the problem itself. Please forgive the wordiness! I'm trying to build gcc to run on Win32 and produce code for AVR. I've ...
HiTechHiTouch's user avatar
3 votes
1 answer
1k views

Issuing commands with options determined by condition

I am trying to make a shell script which will ask some questions to the user, and will issue a final command with some or other options depending on what the user chose. Right now, the script looks ...
Jeffrey Lebowski's user avatar
2 votes
2 answers
36k views

Explanation of options(flags) for bash [closed]

I often see scripts with usage of options as in if [ -f some_file ] checks whether some_file is a file. I have a very vague understandings of flags, but can someone give me a good explanation? Others ...
夢のの夢's user avatar
1 vote
2 answers
73 views

Should the operands to a utility always appear after all the options to the utility?

POSIX says utility_name[-a][-b][-c option_argument] [-d|-e][-f[option_argument]][operand...] ... The arguments following the last options and option-arguments are named "operands". ...
Tim's user avatar
  • 105k
5 votes
2 answers
7k views

How does the -d option to bash read work?

I have a bash script where I'm trying to assign a heredoc string to a variable using read, and it only works if I use read with the -d '' option, I.e. read -d '' <variable> script block #!/...
the_velour_fog's user avatar
3 votes
2 answers
1k views

Can a bash array be used in place of eval set -- "$params"?

I'm taking a look at the optparse library for bash option parsing, specifically this bit in the generated code: params="" while [ $# -ne 0 ]; do param="$1" shift case "$param" in --my-...
Wildcard's user avatar
  • 37k
14 votes
2 answers
37k views

Linux command to display the contents of a given file byte by byte with the character and its numerical representation displayed for each byte [closed]

I am looking for the Linux command and option combination to display the contents of a given file byte by byte with the character and its numerical representation. I was under the impression that in ...
alxmke's user avatar
  • 243
2 votes
2 answers
1k views

Function with many arguments but only one switch

I am effectively making a recycling bin via some scripts I made. The first script is pretty much an alternative to the rm command (instead of actually deleting a file, it moves it to a deleted folder)...
user3120554's user avatar
2 votes
3 answers
6k views

How to extract unknown arguments within a shell script?

I have a shell script that accepts a variety of options, some with arguments, some without, some short, some long. It should handle some of these options itself and pass on the rest it does not know ...
XZS's user avatar
  • 1,448
3 votes
1 answer
2k views

Strange leading whitespace in OPTARG when using getopts

I spent quite a while researching the problem I encountered but none of the getopts tutorial say anything about the leading whitespace in OPTARG when using getopts. In bash(on Ubuntu and OSX), ...
GJ.'s user avatar
  • 153
0 votes
1 answer
773 views

Is there a command which displays options like `errexit` and `braceexpand` other than `help set`?

If you type help set, then - among other things - a list of shell options is displayed. But these options are not the same as those displayed with shopt. And different also from those displayed with ...
AmadeusDrZaius's user avatar
8 votes
2 answers
11k views

Passing arguments to su-provided shell

man su says: You can use the -- argument to separate su options from the arguments supplied to the shell. man bash says: -- A -- signals the end of options and disables further option ...
x-yuri's user avatar
  • 3,513
3 votes
4 answers
4k views

Parsing process command-line arguments from pargs in a shell script

I get list of PIDs in my bash scripts (Java processes) and have to analyze their command-line arguments to determine which instance of server each PID corresponds to. At the moment I do it that way ...
user1065145's user avatar
1 vote
1 answer
718 views

bash control statment for when an option flag is used

I trying to make control statement to check on a option flag is used or not? For -o output.file if is used I would like to make equal to variable OUTPUTSUM = OUTPUTFILE and if there no -o option use ...
MAXGEN's user avatar
  • 215
9 votes
2 answers
14k views

Privileged mode in bash

I've used bash for years but I 've stuck with the"privileged mode" that it can be configure with the set command. For example: set -p I've read the bash man page but it's somewhat obscure. For ...
sebelk's user avatar
  • 4,579
31 votes
2 answers
40k views

What is the difference between "du -sh *" and "du -sh ./*"?

What's the difference between du -sh * and du -sh ./* ? Note: What interests me is the * and ./* parts.
Biswanath's user avatar
  • 511