Sponsored Content
Full Discussion: Remove file called "-X"??
Top Forums Shell Programming and Scripting Remove file called "-X"?? Post 302504538 by alister on Monday 14th of March 2011 09:29:04 PM
Old 03-14-2011
In general, when dealing with arguments which look like options, you can use a double dash to signal the end of options:

Code:
command -o1 -o2 -- -X

In that case, -o1 and -o2 are two option-arguments to command. -- signals the end of options. Since -X appears after --, it is not considered an option-argument even though it begins with a dash.

One way to create that file and then remove it:
Code:
touch -- -X
rm -- -X

Regards,
Alister
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

2. Windows & DOS: Issues & Discussions

Samba (SMB) client fails: "Called name not present"

Hi, I issue smbclient on a Linux REd hat server : smbclient -L ***.16.0.42 -U domaine/Administrator Password: Domain= OS= Server= Domain= OS= Server= Sharename Type Comment --------- ---- ------- IPC$ IPC IPC distant ... (0 Replies)
Discussion started by: big123456
0 Replies

3. UNIX for Advanced & Expert Users

All alias in .profile lost when "script" command is called

Hi, I was trying to call "script <an ip add>" command from .profile file to log everything whenever anyone logs in to this user. I did the following at the end of .profile. 1) Extracted the IP address who logged in 2) Called script < ip add> . The problem I am facing is all, aliases etc. written... (3 Replies)
Discussion started by: amicon007
3 Replies

4. UNIX for Advanced & Expert Users

How to remove a directory called "--"

I need to remove a directory called "--"". But it seems "--" linked to /export/home/usr1, which I do not want to delete. How to rm "--" safely? The OS is Solaris 9. Thanks. (6 Replies)
Discussion started by: fld2007
6 Replies

5. UNIX for Advanced & Expert Users

Rename file called "-X"??

Hi all, So I have found a file literally called "-X" in a folder, that is preventing me from using any meaningful commands in that folder because, as I understand it, at command runtime it will convert any wildcard characters into matching filenames, thus a command such as: ls *Ends up... (1 Reply)
Discussion started by: dan-e
1 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

8. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

9. Linux

Read only access for Group called "Developers" to all folders on the Centos 6.6

Linux Gurus, I need to provide Read only access for particular group of users, they should have Read only access to entire server except their Home directory. I tried using setfacl that's not helping. Can you please suggest is there any other alternate way to address this request. Your help is... (5 Replies)
Discussion started by: shekar777
5 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
GETOPT(3)						     Library Functions Manual							 GETOPT(3)

NAME
getopt - get option character from command line argument list SYNOPSIS
#include <stdlib.h> extern char *optarg; extern int optind; extern int optopt; extern int opterr; extern int optreset; int getopt(argc, argv, optstring) int argc; char **argv; char *optstring; DESCRIPTION
The getopt() function incrementally parses a command line argument list argv and returns the next known option character. An option char- acter is known if it has been specified in the string of accepted option characters, optstring. The option string optstring may contain the following elements: individual characters, and characters followed by a colon to indicate an option argument is to follow. For example, an option string """x"" recognizes an option ``-x'', and an option string """x:"" recognizes an option and argument ``-x argument''. It does not matter to getopt() if a following argument has leading white space. On return from getopt(), optarg points to an option argument, if it is anticipated, and the variable optind contains the index to the next argv argument for a subsequent call to getopt(). The variable optopt saves the last known option character returned by getopt(). The variable opterr and optind are both initialized to 1. The optind variable may be set to another value before a set of calls to getopt() in order to skip over more or less argv entries. In order to use getopt() to evaluate multiple sets of arguments, or to evaluate a single set of arguments multiple times, the variable optreset must be set to 1 before the second and each additional set of calls to getopt(), and the variable optind must be reinitialized. The getopt() function returns an EOF when the argument list is exhausted, or a non-recognized option is encountered. The interpretation of options in the argument list may be cancelled by the option `--' (double dash) which causes getopt() to signal the end of argument process- ing and return an EOF. When all options have been processed (i.e., up to the first non-option argument), getopt() returns EOF. DIAGNOSTICS
If the getopt() function encounters a character not found in the string optarg or detects a missing option argument it writes an error mes- sage and returns `?' to the stderr. Setting opterr to a zero will disable these error messages. If optstring has a leading `:' then a missing option argument causes a `:' to be returned in addition to suppressing any error messages. Option arguments are allowed to begin with `-'; this is reasonable but reduces the amount of error checking possible. EXTENSIONS
The optreset variable was added to make it possible to call the getopt() function multiple times. This is an extension to the IEEE Std1003.2 (``POSIX'') specification. EXAMPLE
extern char *optarg; extern int optind; int bflag, ch, fd; bflag = 0; while ((ch = getopt(argc, argv, "bf:")) != EOF) switch(ch) { case 'b': bflag = 1; break; case 'f': if ((fd = open(optarg, O_RDONLY, 0)) < 0) { (void)fprintf(stderr, "myname: %s: %s ", optarg, strerror(errno)); exit(1); } break; case '?': default: usage(); } argc -= optind; argv += optind; HISTORY
The getopt() function appeared 4.3BSD. BUGS
A single dash ``-'' may be specified as an character in optstring , however it should never have an argument associated with it. This allows getopt() to be used with programs that expect ``-'' as an option flag. This practice is wrong, and should not be used in any cur- rent development. It is provided for backward compatibility only . By default, a single dash causes getopt() to return EOF. This is, we believe, compatible with System V. It is also possible to handle digits as option letters. This allows getopt() to be used with programs that expect a number (``-3'') as an option. This practice is wrong, and should not be used in any current development. It is provided for backward compatibility only. The following code fragment works in most cases. int length; char *p; while ((c = getopt(argc, argv, "0123456789")) != EOF) switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) length = atoi(++p); else length = atoi(argv[optind] + 1); break; } } 4.3 Berkeley Distribution January 12, 1996 GETOPT(3)
All times are GMT -4. The time now is 10:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy