Using Double Dash To Specify Pesky Ascendence Describe Of Piece Of Employment Parameters

Many Linux commands convey command-line options together with positional parameters. The grep ascendance searches for a blueprint inward a given file. Its two positional parameters are the blueprint together with the filename. It accepts options such every bit -i which specifies that the search is instance insensitive.

An interesting scenario is when a positional parameter has a value starting amongst a dash ('-'). This makes the parameter indistinguishable from an option. For example, y'all campaign to grep the string -tea inward a given file.

$ grep -i '-tea' test.txt grep: invalid pick -- 't' Usage: grep [OPTION]... PATTERN [FILE]... Try 'grep --help' for to a greater extent than information.

The -tea is interpreted every bit an option. Consequently, the ascendance failed.

To solve the problem, insert the double dash (--) on the ascendance describe of piece of job to reach the halt of all options. Everything that come upward afterwards the -- mark are interpreted every bit positional parameters.

$ grep -i -- '-tea' test.txt Beverages -tea together with coffee- are served.

Anther instance scenario for using the double dash is the deleting of a file amongst a pesky file name. Suppose y'all desire to delete a file named '-a'.

$ rm -a rm: invalid pick -- 'a' Try `rm --help' for to a greater extent than information.

Enter -- to reach where the positional parameters start.

$ rm -- -a

Berlangganan update artikel terbaru via email:

0 Response to "Using Double Dash To Specify Pesky Ascendence Describe Of Piece Of Employment Parameters"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel