Monday, April 29, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 7059  / 2 Years ago, wed, june 22, 2022, 4:55:58

When trying to open a file with sudo gedit /path/to/file with a file name starting with a ! in front eg !config.ini i can not open the file. However if i do sudo nautilus then open the file with gedit it opens.If the file is renamed config.ini sudo gedit again works.Could someone explain this to me please.


More From » command-line

 Answers
5

You are entering the sudo gedit /path/to/file command into a shell (by default bash), but modern shells use the '!' character for special purposes. Special characters can be interpreted without special meaning by preceding them with the '' character.



Try:



gksudo gedit /path/to/!file


instead of



gksudo gedit /path/to/!file


In modern shells the commands you enter are remembered and you can reenter them by using the '!' character. !! for example reenters the last command. As Uri points out, this is called an event designator. The bash interpreter also let's you use Ctrl+R to easily find commands you want to reenter, but the '!' mechanism is still there for us old-timers who have the habit of using '!' instead. Other uses of "!" include the $! parameter, and its use in arithmetic and logical expressions.



A bash reference may be helpful if you run into such mysteries because shells can be very complicated. The gnu bash manual is here.



Uri helpfully mentioned that you should use gksu or gksudo rather than sudo. There is an explanation here: What is the difference between "gksudo nautilus" and "sudo nautilus"?.


[#36385] Thursday, June 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
enincroscope

Total Points: 252
Total Questions: 124
Total Answers: 104

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
enincroscope questions
Thu, Jan 20, 22, 08:33, 2 Years ago
Thu, Apr 7, 22, 01:09, 2 Years ago
Mon, May 16, 22, 09:08, 2 Years ago
;