Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
1
votes
1
answers
116
views
Shell script with getopt for short and long options -handling option with and without argument
Wanted to run a script -- with option `./myscript.sh -a -g test` -- without option `./myscript.sh -a -g` The script looks like in below snippet, but don't see below script working correctly. The `getopt` for options specified with `::` (like g:: or gamma::) upon parsing g or gamma the passed argumen...
Wanted to run a script
-- with option
./myscript.sh -a -g test
-- without option
./myscript.sh -a -g
The script looks like in below snippet, but don't see below script working correctly.
The getopt
for options specified with ::
(like g:: or gamma::) upon parsing g or gamma the passed argument is moved to end every time includes empty argument user option: --gamma '' -a -- 'test'
.
Refer the output of the script
$ sh optionwithandwithoutarg.sh --gamma test -a
user option: --gamma '' -a -- 'test'
arg info :- --gamma
arg info :- -a
arg info :- --
Alpha flag: true
Beta value: ''
Gamma value: 'default_gamma'
Remaining arguments: 'test'
## Script code used
#!/bin/bash
OPTIONS=$(getopt -o a,g::,b: --long alpha,gamma::,beta: --name "$0" -- "$@")
if [ $? -ne 0 ]; then
echo "Error: Invalid options provided."
exit 1
fi
echo "user option: $OPTIONS"
eval set -- "$OPTIONS"
# Initialize variables
ALPHA_FLAG="false"
BETA_VALUE=""
GAMMA_VALUE=""
while true; do
echo "arg info :- $1"
case "$1" in
-a | --alpha)
ALPHA_FLAG="true"
shift
;;
-b | --beta)
BETA_VALUE="$2"
shift 2
;;
-g | --gamma)
if [[ "$2" != "--" && -n "$2" ]]; then
GAMMA_VALUE="$2"
shift 2
else
GAMMA_VALUE="default_gamma" # Assign a default if no argument given
shift 2
fi
;;
--)
shift
break
;;
*)
echo "Not supported option"
exit 1
;;
esac
done
echo "Alpha flag: $ALPHA_FLAG"
echo "Beta value: '$BETA_VALUE'"
echo "Gamma value: '$GAMMA_VALUE'"
echo "Remaining arguments: '$*'"
How to handle the options with and without argument with getopt
Tim
(113 rep)
Aug 2, 2025, 02:26 PM
• Last activity: Aug 4, 2025, 10:38 AM
177
votes
5
answers
307856
views
How can I execute local script on remote machine and include arguments?
I have written a script that runs fine when executed locally: ./sysMole -time Aug 18 18 The arguments **"-time"**, **"Aug"**, **"18"**, and **"18"** are successfully passed on to the script. Now, this script is designed to be executed on a remote machine but, from a local directory on the local mach...
I have written a script that runs fine when executed locally:
./sysMole -time Aug 18 18
The arguments **"-time"**, **"Aug"**, **"18"**, and **"18"** are successfully passed on to the script.
Now, this script is designed to be executed on a remote machine but, from a local directory on the local machine. Example:
ssh root@remoteServer "bash -s" < /var/www/html/ops1/sysMole
That also works fine. But the problem arises when I try to include those aforementioned arguments **(-time Aug 18 18)**, for example:
ssh root@remoteServer "bash -s" < /var/www/html/ops1/sysMole -time Aug 18 18
After running that script I get the following error:
bash: cannot set terminal process group (-1): Invalid argument
bash: no job control in this shell
Please tell me what I'm doing wrong, this greatly frustrating.
AllenD
(2507 rep)
Aug 20, 2013, 01:52 AM
• Last activity: Jun 22, 2025, 07:27 PM
5
votes
2
answers
6356
views
What does Linux's "nointremap" option do?
Ubuntu 12.10 alpha 2 works perfectly on my new 11" 2012 Macbook Air, but only when I boot with the "nointremap" option. Supposedly this is not good to use as a permanent solution. What exactly does this option do, and why is it "bad"?
Ubuntu 12.10 alpha 2 works perfectly on my new 11" 2012 Macbook Air, but only when I boot with the "nointremap" option. Supposedly this is not good to use as a permanent solution. What exactly does this option do, and why is it "bad"?
Zifre
(336 rep)
Jul 19, 2012, 10:27 PM
• Last activity: May 11, 2025, 09:02 PM
0
votes
2
answers
114
views
passing long positional arguments in bash script
I would like to pass long arguments to script, and referred this [link][1]. I created this my_script: ``` #!/usr/bin/env bash # # Adapted from https://www.shellscript.sh/examples/getopt/ # set -euo pipefail user_type=unset user_id=unset country=unset dev_env=unset position_id=unset usage(){ >&2 cat...
I would like to pass long arguments to script, and referred this link . I created this my_script:
#!/usr/bin/env bash
#
# Adapted from https://www.shellscript.sh/examples/getopt/
#
set -euo pipefail
user_type=unset
user_id=unset
country=unset
dev_env=unset
position_id=unset
usage(){
>&2 cat &2 echo [$@] passed to script
args=$(getopt -a -o ha:b:c:d: --long help,user_type:,user_id:,country:,dev_env:,position_id: -- "$@")
if [[ $? -gt 0 ]]; then
usage
fi
>&2 echo getopt creates [${args}]
eval set -- ${args}
while :
do
case $1 in
-a | --user_type) user_type=$2 ; shift 2 ;;
-b | --user_id) user_id=$2 ; shift 2 ;;
-h | --help) usage ; shift ;;
-c | --country) country=$2 ; shift 2 ;;
-d | --dev_env) dev_env=$2 ; shift 2 ;;
-e | --position_id) position_id=$2 ; shift 2 ;;
# -- means the end of the arguments; drop this, and break out of the while loop
--) shift; break ;;
*) >&2 echo Unsupported option: $1
usage ;;
esac
done
if [[ $# -eq 0 ]]; then
usage
fi
>&2 echo "user_type : ${user_type}"
>&2 echo "user_id : ${user_id} "
>&2 echo "country : ${country}"
>&2 echo "dev_env : ${dev_env}"
>&2 echo "position_id : ${position_id}"
>&2 echo "$# parameter/s remaining: $@"
>&2 echo "Looping through remaining parameter/s:"
# set input field separator to keep quoted parameters together
# for example, "my input" will remain as one input
IFS=$'\n'
for param in $@; do
>&2 echo -e "\t${param}"
done
echo "user ${user_type} with user id ${user_id} has been created with position_id $position_id"
exit 0
and on terminal tried running it as:
bash test_bash --user_type abc --user_id a1b2 --country aud --dev_env uat --position_id aFWf
I am getting just help message like:
[--user_type abc --user_id a1b2 --country aud --dev_env uat --position_id aFWf] passed to script
getopt creates [ --user_type 'abc' --user_id 'a1b2' --country 'aus' --dev_env 'uat' --position_id 'aFWf' --]
Usage: test_bash]
[ -a | --user_type input
[ -b | --user_id input ]
[ -c | --country input ]
[ -d | --dev_env input ]
[ -e | --position_id input ]
I have tried to update/change few things like args=getopt with couple of other options. but I args are not been parsed by script. Appriciate your help in advance. Thanks.
SheCodes
(103 rep)
Mar 24, 2025, 06:47 AM
• Last activity: Mar 25, 2025, 11:17 AM
1
votes
4
answers
140
views
Need shell script help - processing the same option multiple times
So I've ran into a bit of a wall, I have an option in my script that calls a function which allows me to specify a file/directory and then I want to parse that output into a menu tool (using dmenu in this case) to select which file is the one I want specifically and continue working with that select...
So I've ran into a bit of a wall, I have an option in my script that calls a function which allows me to specify a file/directory and then I want to parse that output into a menu tool (using dmenu in this case) to select which file is the one I want specifically and continue working with that selection as a variable
in the same script. This works fine if it's just one file or directory, but I want to be able to use the option multiple times and then parse all of that output at once to dmenu. Here's a snippet
fileSelection () {
if [ -d "${OPTARG}" ]; then find "${OPTARG}" -type f; fi;
if [ -f "${OPTARG}" ]; then printf '%s\n' "${OPTARG}"; fi;
}
while getopts "f:" option; do
case "${option}" in
f) file="$(fileSelection|dmenu)";;
esac
done
And like I said this works if I do:
myscript -f file
or
myscript -f directory
but I was hoping to also be able to do this:
myscript -f file1 -f file2
The problem is, since the function is called consecutively I can't parse the output into dmenu like that, because it doesn't invoke dmenu with options file1 and file2, but first with file1 and then with file2, I hope this makes sense.
There might be some really simple solution I am missing, I've thought about simply writing the output into a file and then parsing that which might work, but I'd like to avoid piping to files if possible. I am also trying to keep it POSIX compliant, and would appreciate answers that follow that.
hollowillow
(11 rep)
Mar 18, 2025, 10:09 PM
• Last activity: Mar 20, 2025, 07:58 PM
0
votes
2
answers
4834
views
-y in Linux for example dnf -y install samba
what does the -y mean in linux. this symbol is always used after a command for example dnf -y install httpd. Everywhere I have looked I cannot find a definite answer. Please help
what does the -y mean in linux. this symbol is always used after a command for example dnf -y install httpd.
Everywhere I have looked I cannot find a definite answer. Please help
Marty Kutzbach
(17 rep)
Sep 16, 2019, 10:16 PM
• Last activity: Mar 12, 2025, 09:16 PM
4
votes
2
answers
7348
views
What precisely does cp -b (--backup) actually do?
Before you hit me with the obvious, I know, the backup option makes a backup of a file. But the thing is, the `cp` command in general backs up a file. One could argue a copy of a file is a backup. So more precisely, my question is this: what does the `-b` option do that the `cp` command doesn't do a...
Before you hit me with the obvious, I know, the backup option makes a backup of a file.
But the thing is, the
cp
command in general backs up a file. One could argue a copy of a file is a backup.
So more precisely, my question is this: what does the -b
option do that the cp
command doesn't do already?
The cp(1) man page gives the following description of the --backup
option:
> make a backup of each existing destination file
This definition isn't very useful, basically saying "the backup option makes a backup". This gives no indication as to what -b
adds to the cp
I know -b
puts some suffix at the end of the name of the new file. But is there anything else it does? Or is that it? Is a -b
backup just a cp
command that adds something to the end of the filename?
P.S. Do you typically use -b
when making backups in your daily work? Or do you just stick to -a
?
backslash enn
(43 rep)
Feb 1, 2023, 05:44 PM
• Last activity: Mar 1, 2025, 02:51 PM
5
votes
4
answers
882
views
Pass multiple files as a single option
I'm trying to build a wrapper to execute a tool multiple times, then concatenate some of the results. I'd like to pass two sets of files to my wrapper script, then run the tool for each pair of files. I'd like it to behave like this: `multitool.sh -a a*.txt -b b*.txt` (expanding the wildcards to mat...
I'm trying to build a wrapper to execute a tool multiple times, then concatenate some of the results. I'd like to pass two sets of files to my wrapper script, then run the tool for each pair of files. I'd like it to behave like this:
multitool.sh -a a*.txt -b b*.txt
(expanding the wildcards to match all files available)
Then inside multitool.sh
, I run the tool on a1.txt b1.txt
, a2.txt b1.txt
, a1.txt b2.txt
, a2.txt b2.txt
, etc, with variable numbers of a and b files.
I followed [this](https://www.redhat.com/en/blog/arguments-options-bash-scripts) tutorial explaining the basics of option handling, and I'm able to use getops
to handle a -h
, but nothing else.
Here is where I'm at now:
#!/bin/bash
while getopts ":hpg:" option; do
case $option in
h) # display help
echo "-h to print this help and exit, -p is peak files, -g is bedgraph files."
exit;;
p) # get list of peak files to process
l_peaks=$OPTARG;;
g) # get list of bedgraph files to process
l_bgraphs=$OPTARG;;
\?) # Invalid option
echo "Error! Invalid option!"
echo "-h to print this help and exit, -p is peak files, -g is bedgraph files."
exit;;
esac
done
echo "$l_peaks"
echo "$l_bgraphs"
I'm working with a team who aren't particularly computer literate, so if I can keep the wrapper to a simple one line execution, that would be best.
How can I pass these lists of files as one option each?
Whitehot
(245 rep)
Feb 24, 2025, 01:09 PM
• Last activity: Feb 25, 2025, 07:08 AM
1
votes
2
answers
58
views
The ambiguous principles that guide the lsblk utility in removing duplicates of displayed records
Linux Mint 20.3 > lsblk -V > > lsblk from util-linux 2.34 Let's find an explanation for the ambiguous behavior of the **lsblk** utility applied with the *-E* option. Here is the output without applying the *-E* option. You can see that there are repeated entries in the SIZE column. These are (loop0...
Linux Mint 20.3
> lsblk -V
>
> lsblk from util-linux 2.34
Let's find an explanation for the ambiguous behavior of the **lsblk** utility applied with the *-E* option.
Here is the output without applying the *-E* option.
You can see that there are repeated entries in the SIZE column. These are (loop0 loop2) and (loop6 loop10).
greg@mynt23:~$ lsblk -o NAME,SIZE
NAME SIZE
loop0 164,8M
loop1 4K
loop2 164,8M
loop3 55,4M
loop4 73,9M
loop5 66,2M
loop6 449M
loop7 91,7M
loop8 44,4M
loop9 40,9M
loop10 449M
loop11 74,1M
loop12 55,7M
sda 298,1G
├─sda1 4,9G
├─sda2 104,2G
└─sda3 189,1G
Now apply the *-E* option.
greg@mynt23:~$ lsblk -o NAME,SIZE -E SIZE
NAME SIZE
loop1 4K
loop3 55,4M
loop4 73,9M
loop5 66,2M
loop7 91,7M
loop8 44,4M
loop9 40,9M
loop11 74,1M
loop12 55,7M
sda 298,1G
├─sda1 4,9G
├─sda2 104,2G
└─sda3 189,1G
The repeated entries from the SIZE column disappeared completely, instead leaving one "original" entry. The entries left should have been loop0 and loop6.
Apply RM or TYPE as a key. You will see that all duplicates are removed, but the "original" entry is left. The manual says that duplicates are removed, not duplicates along with what the duplicates duplicate.
How do we explain it?
Kiki Miki
(27 rep)
Feb 5, 2025, 12:13 AM
• Last activity: Feb 5, 2025, 11:22 AM
4
votes
2
answers
678
views
Are Shell Script --long-options POSIX compatible?
In almost all POSIX specifications (e.g. [ls][1]), there are only short options (e.g. -A , -a , etc). In common shells like [Bash][2], long options (e.g. --all , --almost-all , etc) are very common. And it is recommended to write Shell Scripts with long options for better readability. However, is it...
In almost all POSIX specifications (e.g. ls ), there are only short options (e.g. -A , -a , etc). In common shells like Bash , long options (e.g. --all , --almost-all , etc) are very common. And it is recommended to write Shell Scripts with long options for better readability. However, is it possible that using long options makes the shell scripts cannot run on certain, may be old version shell or environment with less resources like Android ADB, yet POSIX compatible Shells?
In addition, I notice that FreeBSD man pages (e.g. ls ), most of the long options are not available. Does FreeBSD support long options? (I do not have FreeBSD for testing.)
midnite
(613 rep)
Jan 2, 2025, 04:40 PM
• Last activity: Jan 7, 2025, 11:34 AM
22
votes
8
answers
23480
views
Compiling GNU/Linux with -O3 optimization
It's said that compiling GNU tools and Linux kernel with `-O3` gcc optimization option will produce weird and funky bugs. Is it true? Has anyone tried it or is it just a hoax?
It's said that compiling GNU tools and Linux kernel with
-O3
gcc optimization option will produce weird and funky bugs. Is it true? Has anyone tried it or is it just a hoax?
uray
(3958 rep)
Sep 4, 2010, 09:53 PM
• Last activity: Dec 30, 2024, 11:29 AM
0
votes
1
answers
68
views
zsh auto completion of cp options doesn't list all of them
I've been working on setting my autocmp following this guide https://thevaluable.dev/zsh-install-configure-mouseless/. I'm on a MacOS environment but for some reason when I try to autocomplete options it doesn't list the complete set of options. This is my config for autocomplete: ``` #Completion au...
I've been working on setting my autocmp following this guide https://thevaluable.dev/zsh-install-configure-mouseless/ . I'm on a MacOS environment but for some reason when I try to autocomplete options it doesn't list the complete set of options. This is my config for autocomplete:
#Completion
autoload -Uz compinit
compinit
zmodload zsh/complist
#Amazing article https://thevaluable.dev/zsh-install-configure-mouseless/
zstyle ':completion:*' completer _extensions _complete _approximate
zstyle ':completion:*' menu select
zstyle ':completion:*' file-sort modification
zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f'
zstyle ':completion:*' complete-options true
zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*' #https://unix.stackexchange.com/a/259511
zstyle ':completion:*' verbose yes
zstyle ':completion:*' group-name ''
zstyle ':completion:*' list-colors 'di=34:fi=31:no=33;00'
# zstyle ':completion:*' file-list all #Unfortunetly this messes up colouring
#Move with VIM keys Autocompletion
bindkey '^[[Z' reverse-menu-complete
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
When I try to autocomplete options for builtin shell commands I get the following:
❯ cp -
-- option --
-H -- follow symlinks on the command line in recursive mode
-L -- follow all symlinks in recursive mode
-P -- do not follow symlinks in recursive mode (default)
-R -- copy directories recursively
-X -- don\'t copy extended attributes or resource forks
-a -- archive mode, same as -RpP
-f -- force overwriting existing file
-i -- confirm before overwriting existing file
-n -- don\'t overwrite existing file
-p -- preserve timestamps, mode, owner, flags, ACLs, and extended attributes
-v -- show file names as they are copied
I would expect to get the complete list of cp
options as per the article. Is this possibly a MacOs issue for completion for zsh?
Andrés
(3 rep)
Dec 19, 2024, 05:03 PM
• Last activity: Dec 19, 2024, 08:51 PM
0
votes
1
answers
12696
views
What does -n flags stands for after echo?
I have the following code snippet: ``` #!/bin/sh if [ $1 = hi ]; then echo 'The first argument was "hi"' else echo -n 'The first argument was not "hi" -- ' echo It was '"'$1'"' fi ``` And I don't know what the flag -n after echo in the else statement stands for, does anyone knows the answer? Thank y...
I have the following code snippet:
#!/bin/sh
if [ $1 = hi ]; then
echo 'The first argument was "hi"'
else
echo -n 'The first argument was not "hi" -- '
echo It was '"'$1'"'
fi
And I don't know what the flag -n after echo in the else statement stands for,
does anyone knows the answer?
Thank you very much!
almrog
(19 rep)
Apr 12, 2020, 08:58 PM
• Last activity: Dec 6, 2024, 01:16 PM
15
votes
4
answers
13616
views
Copying image from scrot into clipboard after capture
I've grown affection to scrot as a simple screenshot utility, but it lacks one thing i would greatly appreciate--a way to copy your capture and have it in your clipboard automatically. I've added a line to .bash_aliases that automatically puts it in the folder i desire, and also have it always run i...
I've grown affection to scrot as a simple screenshot utility, but it lacks one thing i would greatly appreciate--a way to copy your capture and have it in your clipboard automatically.
I've added a line to .bash_aliases that automatically puts it in the folder i desire, and also have it always run in selection mode, but there seems to be no flag for copying the result after capturing. Is there any way to do this?
.bash_alias entry=
scrot='scrot -s ~/Pictures/%b%d::%H%M%S.png'
lcdhead
(151 rep)
Dec 8, 2020, 07:26 PM
• Last activity: Nov 6, 2024, 05:31 PM
2
votes
2
answers
7818
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 fallback value will be applied. ``` command -n 100 command -n ``` I can only make the former input...
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 fallback value will be applied.
command -n 100
command -n
I can only make the former input type work or the latter, but not both.
HAS_NICE_THINGS=0
NICE_THINGS=50 # default value.
while getopts n: option; do
#while getopts n option; do # NICE_THINGS would always be that default value.
#while getopts nn: option; do # same.
case "${option}" in
n)
HAS_NICE_THINGS=1
if [[ ! -z "${OPTARG}" ]] && (( "${OPTARG}" > 0 )) && (( "${OPTARG}" <= 100 )); then
NICE_THINGS=${OPTARG}
fi;;
esac
done
# error message:
# option requires an argument -- n
I'm not entirely sure yet if I would need a boolean for my script, but so far, just in case, I am logging one (HAS_NICE_THINGS
).
The end goal I had in mind was to set the JPG quality when eventually saving an image. Though, I can imagine this construct being useful elsewhere as well.
I'm using Ubuntu 18.04.5
and GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
.
WoodrowShigeru
(261 rep)
Aug 8, 2021, 01:09 PM
• Last activity: Oct 3, 2024, 01:10 PM
11
votes
1
answers
962
views
Confusion about changing meaning of arguments and options, is there an official standard definition?
I came across a confusing variation in the understanding what options and arguments are with regard to the syntax of commands. For instance, I encountered definitions like: - `command -a -b -c d e f` some differ between `-a -b -c`, call them options or switches and `d e f` by calling them arguments....
I came across a confusing variation in the understanding what options and arguments are with regard to the syntax of commands.
For instance, I encountered definitions like:
-
command -a -b -c d e f
some differ between -a -b -c
, call them options or switches and d e f
by calling them arguments.
- command -a -b -c d e f
some, for instance a bash
manual, call all -a -b -c d e f
arguments and explains, that all of them are accessible from a script by $1 $2 $3 $4 $5 $6
respectively.
- command -a b=c
some call -a
an option, b
an argument and c
the value, but others mix them like in the first two points, in one variety calling all -a b c
arguments.
Those three versions are only examples for a plethora of different calling varieties, I do not even know how to list them all, but I noticed that for sure there is no fixed naming convention.
Or at least, there is no standardised naming convention I know about, because I came across different random sources, but even among official Linux and GNU affiliated sites or manuals I could met this inconsistency.
Is there a unquestionable official naming scheme I can refer to?
sharkant
(3810 rep)
May 11, 2017, 10:30 AM
• Last activity: Aug 20, 2024, 06:00 AM
0
votes
0
answers
44
views
what is a "flag" in bash? and how is it different then other options? what would be a good example to highlight the difference?
so i keep hearing that a flag is a TYPE of option, and that the only difference between a flag and normal options is that a flag is a type of "boolean" option, which when explained to me seems no different then binary so what is a flag? how is it different then other options? what would be a good ex...
so i keep hearing that a flag is a TYPE of option, and that the only difference between a flag and normal options is that a flag is a type of "boolean" option, which when explained to me seems no different then binary
so what is a flag? how is it different then other options?
what would be a good example to show someone in the terminal the difference between flags and other types of options?
thank you
how to bash
(9 rep)
Aug 20, 2024, 12:50 AM
• Last activity: Aug 20, 2024, 05:54 AM
78
votes
5
answers
69974
views
getopt, getopts or manual parsing - what to use when I want to support both short and long options?
Currently I'm writing a Bash script which has the following requirements: * it should run on a wide variety of Unix/Linux platforms * it should support both short and (GNU) long options I know that `getopts` would be the preferred way in terms of portability but AFAIK it doesn't support long options...
Currently I'm writing a Bash script which has the following requirements:
* it should run on a wide variety of Unix/Linux platforms
* it should support both short and (GNU) long options
I know that
getopts
would be the preferred way in terms of portability but AFAIK it doesn't support long options.
getopt
supports long options but the BashGuide recommends strongly against it:
> Never use getopt(1). getopt cannot handle empty arguments strings, or
> arguments with embedded whitespace. Please forget that it ever
> existed.
So, there still is the option of manual parsing. This is error-prone, produces quite some boilerplate code, and I need to handle errors by myself (I guess getopt(s)
do error-handling by themselves).
So, what would be the preferred choice in this case?
helpermethod
(2052 rep)
Jan 29, 2013, 11:37 AM
• Last activity: Aug 13, 2024, 01:54 PM
14
votes
2
answers
8895
views
grepping for word starting with hyphen gives error: invalid option -- 't'
When I grep the man page of the `find` command for matches to `type` it returns a lot of search results that I don't want. Instead I want to use a command that returns *only* the search results for `-type`. The command `man find | grep -type` doesn't work. It returns: grep: invalid option -- 't'
When I grep the man page of the
find
command for matches to type
it returns a lot of search results that I don't want. Instead I want to use a command that returns *only* the search results for -type
.
The command man find | grep -type
doesn't work. It returns:
grep: invalid option -- 't'
karel
(2038 rep)
Nov 17, 2016, 11:13 PM
• Last activity: Jul 5, 2024, 08:34 AM
26
votes
4
answers
53416
views
How do I handle switches in a shell script?
Are there some built-in tools that will recognize `-x` and `--xxxx` as switches (*flags* or "boolean options", rather than "ordinary arguments"), or do you have to go through all the arguments, test for dashes, and then parse the rest thereafter?
Are there some built-in tools that will recognize
-x
and --xxxx
as switches (*flags* or "boolean options", rather than "ordinary arguments"), or do you have to go through all the arguments, test for dashes, and then parse the rest thereafter?
user394
(14722 rep)
Sep 18, 2011, 06:47 PM
• Last activity: Jun 13, 2024, 09:31 AM
Showing page 1 of 20 total questions