date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,512,206,558,000 |
I have set up fprintd and added a fingerprint profile, but now I am stuck: how do I get this to let me log in? I have added
auth sufficient pam_unix.so try_first_pass likeauth nullok
auth sufficient pam_fprintd.so
at the beginning of /etc/pam.d/sddm as suggested here which did not change anything (I did use a tab bet... |
I found the answer myself! Here it is. In case that link goes dead, here is the text:
Install the applications needed:
sudo apt install -y fprintd libpam-fprintd
sudo pam-auth-update
Once install finishes, open /etc/pam.d/common-auth for editing
$ sudoedit /etc/pam.d/common-auth
auth [success=1 default=ignore] pam_un... | How do I implement `fprintd` into login in Kubuntu? |
1,512,206,558,000 |
The command
ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub
prints the 128-bit fingerprint of the RSA key.
What is the command to get the 160-bit fingerprint of a RSA key?
|
The key fingerprint is a hash of the key material. In a public key file, the key material is the second whitespace-separated field on the line, encoded in base64. The display format for the fingerprint depends on the hash that's being used.
The 128-bit fingerprint uses MD5 and is displayed in hexadecimal. For example,... | 160-bit fingerprint of RSA key |
1,512,206,558,000 |
$ ssh 192.168.29.126
The authenticity of host '192.168.29.126 (192.168.29.126)' can't be established.
ECDSA key fingerprint is SHA256:1RG/OFcYAVv57kcP784oaoeHcwjvHDAgtTFBckveoHE.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
What is the "fingerprint" it is asking for?
|
The question asks whether you trust and want to continue connecting to the host that SSH does not recognise. It gives you several ways of answering:
yes, you trust the host and want to continue connecting to it.
no, you do not trust the host, and you do not want to continue connecting to it.
[fingerprint] means that... | What is the fingerprint ssh is asking for? |
1,512,206,558,000 |
I am using fingerprint scanner with python-validity driver. According to fprintd(1), fingerprint data is stored in /var/lib/fprint/ after enrolling a fingerprint with fprintd-enroll. But I have this folder empty, although scanning works properly.
What I want is to share fingerprint data between two users, because one ... |
I found your question on Google while trying to solve the same problem. fprintd does in fact store fingerprints in /var/lib/fprint/, though maybe it stores fingerprints differently for your fingerprint sensor.
With regards to copying a registered fingerprint to a different user, that is technically not supported by fp... | Where does fprint store fingerprints |
1,512,206,558,000 |
In ssh server and client authentication, key fingerprints are presented in different ways, even using the same command ssh-keygen -lf (in different hosts or as regards different keys).
Representation 1:
$ ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
256 SHA256:3RE3UrGaTAec8H4YnZG7JTlfXpKvl89iexdqzLCyffY root@hostn... |
Older versions of the ssh-keygen utility from OpenSSH displayed only MD5 hashes; the utility now defaults to displaying a SHA256 hash, although you can still select an MD5 hash using the -E option:
user@host:~/.ssh$ ssh-keygen -E md5 -l -f samplekey
2048 MD5:e6:1f:73:0f:14:cb:9a:71:2f:3b:31:b7:3f:58:1c:52 user@host (R... | Several representations for key fingerprint |
1,512,206,558,000 |
I tried to use my fingerprint reader on my laptop yesterday, installing fprintd ; it didn't work. I then removed all those packackages.
I then realized Gnome (or non graphical session) doesn't ask for my password anymore at login screen, whether I set it on ON or OFF in the GUI parameters.
Could anyone tell me how to ... |
Run the following command:
sudo pam-auth-update
Select the 4 options then validate :
[*] Unix authentication
[*] Register user sessions in the systemd control group hierarchy
[*] GNOME Keyring Daemon - Login keyring management
[*] Inheritabl... | Debian : how to set login behaviour (ask passsword) |
1,512,206,558,000 |
I have a Lenovo Thinkpad T440s, and everything is working pretty much out-of-the-box on Fedora 25, except for the fingerprint scanner. It is detected automatically, and flashes when necessary, and seems to "work", however it never matches my fingerprint (it always says that it is not a match). Is there anything I coul... |
The current release of libfprint(0.6.0) is not working great with the sensors used in recent Lenovo. On my T550, it only ask me to swipe once when enrolling a finger and then fail to recognize it 9/10 times.
If I'm updating to the version in git HEAD it asks me to swipe my finger 5 times and then the recognition is wo... | Fingerprint scanner is detected and seems to be functional, but never matches fingerprint |
1,512,206,558,000 |
I use Fedora 34. I love what fprint is doing when it allows me to authenticate using my fingerprints on my ThinkPad's built-in fingerprint reader, but when I'm in my office, I like to dock my laptop and close the lid. I will use my external monitor, keyboard, and mouse during that time.
However, there are times that I... |
Sorry to disappoint you but, paraphrasing /usr/share/doc/fprintd-pam/README:
Known issues:
* pam_fprintd doesn't support entering either the password or a fingerprint
| How can I type a password when fprint is enabled? |
1,512,206,558,000 |
So when i use lsusb i can find the fingerprint device, the name of it is Generic goodix fingerprint device and my laptop is lenovo thinkpad 530s
considering that lsusb can find it then why can't fprint find it? i just want to use this fingerprint for login authentication, i am using parrot security
|
In the USB standards, there is a well-defined way to get Vendor ID and Product ID numbers from any USB device. lsusb just looks them up in a big table and displays the human-readable texts associated with those entries. The table is typically located at /usr/share/misc/usb.ids or /var/lib/usbutils/usb.ids.
fprint has ... | fprint doesn't find my laptop's fingerprint device but lsusb does? |
1,512,206,558,000 |
I would like to fingerprint some Unix (most are Debian) systems. By fingerprinting I mean run a script that collect material identifiers, system version, etc in order to be able to:
accurately identify machines
discriminate hardware and software modification over machines
I know that a can use couple of commands to... |
On Debian-derived systems, for hardware information use lshw, hwinfo, udevadm, hdparm, inxi (this one needs installing first) etc. To accurately identify machines you may try to use the system serial number, vendor, model, the MAC address of the network controllers, the serial number of the hard disk etc. (You may onl... | How to fingerprint a Unix System [closed] |
1,351,250,142,000 |
I find this a highly annoying "feature" on a wide screen monitor that my mostly used apps - terminal and gedit always open directly under the top-left corner of my screen and I have to drag them to my eye position each and every-time.
I have tried installing the CompizConfig Settings Manager and using the feature to p... |
Actually, since GNOME v3.30 there is a visible option in GNOME Tweaks, which makes it much easier to enable it:
Just select "Center New Windows" under "Windows".
Actually I found a solution for GNOME without compiz.
You can either use
this extension if you have gnome-shell < v3.14
or open dconf and set center-new-w... | Gnome - windows always open top left |
1,351,250,142,000 |
To open a file to edit in gedit I run gedit sample.py &. But with Sublime Text it is simply subl sample.py. This opens the file to edit and it doesn't run in the background (in my shell).
How would I do that with gedit?
I tried exec /usr/bin/gedit "$@" (copied from /usr/bin/subl) but it works like gedit &.
Or alias ge... |
You could use this function:
gedit() { /usr/bin/gedit $@ & disown ;}
It:
Makes a function which can be called with gedit
Launches gedit (using the full path /usr/bin/gedit), passing all the arguments/files given to it using $@
& disown sends it to background and disown detaches it from the terminal/shell.
| How to launch gedit from terminal and detach it (just like "subl" command works)? |
1,351,250,142,000 |
I want to have a shortcut key for duplicating the currently selected line in gedit. Many other editors use Ctrl+D or Ctrl+Shift+D for that, but gedit is different.
Here the default behaviour:
Ctrl+D: removes a line
Ctrl+Shift+D: opens GTK inspector
I am fine with both current behaviours as long as the other hotkey w... |
The plugin mentioned in the comments and the other answer has been recently updated and after install you should be able to use Ctrl+Shift+D to duplicate either a line or a selection.
I've tested it in gedit 3.18.3 on Ubuntu 16.04 but it should work in any version >=3.14.0 even though that's a bit questionable because... | How to get a "duplicate line" hotkey in gedit? |
1,351,250,142,000 |
I am having a dilemma whether to edit a javascript file or not. When I open it with gedit, it shows the following warning:
The file you opened has some invalid characters. If you continue
editing this file you could corrupt this document. You can also choose
another character encoding and try again.
The current ... |
As the file is UTF-8 you could run isutf8. An additional utils package.
It gives you both line, char and offset for bad bytes.
Then use xxd, hexdump or the like to analyze.
Unfortunately it stops at first crash. But then again it depends on the file. Could
be there is only one bad byte ;)
Have some C code that does a ... | How do I scan for invalid characters on gedit? |
1,351,250,142,000 |
Gedit 3.14 in Debian 8 has no window manager decoration and the window cannot be resized. Do I need to install any additional package to make it work or has Gedit become unusable outside of the Gnome desktop? I use the window manager Blackbox.
Edit: Window resizing works in Openbox.
Screenshot:
.
|
Pluma is a Gedit fork without client-side decorations, which means it includes the usual the window borders and title bar.
# apt-get install pluma
Below is a screenshot with the window manager Blackbox.
| Cannot resize Gedit window |
1,351,250,142,000 |
I'm searching for an editor with the ability to spell-check two languages at the same time (German and English). Gedit can't do it out of the box.
But I want to use Gedit. It should be possible by merging the English and German dictionaries and select the created file under Tools->Set Language...
edit
I got it almost... |
Aspell Author Here.
As I said in an earlier answer, you can't just combine dictionaries from different languages and expect it to work. You need to create a new language that combines the features of the two original languages.
Fortunately for English and German this is fairly easy; however, the suggestion quality wi... | Gedit or an other non-commandline editor with the ability to spell-check two languages at the same time |
1,351,250,142,000 |
I need to add a new language in Gedit. The problem is, it is included in Gedit menu of languages now, but its syntax is not highlighted and Gedit is not able to indentify the language just from the file suffix.
I've created both .lang file and a XML file describing MIME-TYPE.
LANG file - /usr/share/gtksourceview-3.0/l... |
Finally I've figured it out. According to GTK lang reference version attribute in <language> tag should be 2.0. And it's really working.
So, the proper <language> tag is this:
<language id="test" _name="Test" version="2.0" _section="Source">
| Adding new language to Gedit |
1,351,250,142,000 |
I'm using RHEL. I want to insert an image in gedit, but I'm not able to do so. Also I'm unable to install LibreOffice because they are asking for a subscription. Any alternate to gedit or can we insert image in gedit.
|
No gedit is strictly a text editor, and does not provide a method for inserting images or embedding images within its files.
I think you're getting confused on the subscription details. The subscription is probably because you're using RHEL, LibreOffice is a free product, you can download the RPMs directly from the pr... | Is it possible to insert image in gedit in Linux? |
1,351,250,142,000 |
I was trying to edit my sources.list in order to add local mirror information. I am not comfortable with command line editors, so I tried using sudo mousepad /etc/apt/sources.list.
I got the following error report.
No protocol specified
(mousepad:4942): Mousepad-ERROR **: Cannot open display:
I tried several other ... |
You shouldn’t run an editor as root to edit system files, you should use sudoedit (especially since you have sudo set up already). That will make a copy of the file, that you can edit, open it in the editor of your choice, wait for you to finish editing it, and if you make changes to it, copy it back over the system f... | Cannot open GUI editors in superuser mode |
1,351,250,142,000 |
Moving from OS X & Textmate to Ubuntu & gedit, the one feature of Textmate I am missing is it's command line tool.
With mate I was able to open a folder as a Textmate project using mate . from within the required directory. This is enormously useful as it speeds up my system navigation considerably.
Is there a way of ... |
This was answered on Superuser, Gedit open current directory from terminal - Ubuntu 10.10. Looks like the answers are still relevant.
| open whole folder in gedit |
1,351,250,142,000 |
How does one find and replace text in all open files with gedit?
|
This is not possible with a stock gedit; there's an open ubuntu brainstorm idea for adding the ability. However, there are plugins that add it, such as advanced-find. If you install that, one of the sections on the "Advanced Find/Replace" dialog is "Scope"; choose "All Opened Documents":
| How does one find and replace text in all open files with gedit? |
1,351,250,142,000 |
I almost always use the Insert spaces instead of tabs feature in gedit. The one exception is when writing a Makefile which requires tabs. I don't suppose there is a way to make this option dependent on the syntax being used? I.e. automatically switch back to tabs when Makefile is detected.
|
There seems to be several ways to handle this.
Modelines
gedit has a modeline plugin. If you enable it you can use the Emacs modeline option Indent-tabs-mode (or any other supported modeline option with the same effect). By setting that option to true you can make gedit indent with tabs for the file in question. So, t... | gedit: tabs or spaces dependent on syntax |
1,351,250,142,000 |
have installed Debian Linux, but gedit is not installed along with it. When I attempt to install gedit using apt-get, it prompts to download many packages up to 370 MB, which is strange. I only want to download gedit in my gnome environmnet, and do not want to have a fresh install of the remaining installed packages l... |
The packages Debian is trying to install are dependencies of gedit: without them, gedit cannot run.
Looks like apt-get wants to download the whole Desktop Environment i.e. the GUI. Evidently you have a minimum install of Debian (without GUI) and now it's asking you for the additional packages: gedit is a graphical ... | gedit installation size is too large |
1,351,250,142,000 |
I'm trying to add the Python plugin trailsave to the text editor Pluma* (which is a Gedit fork) but the plugin doesn't show up in the "Active plugins" list in the Pluma preferences. Also, I have compiled Pluma with Python support. Any ideas?
$ cat ~/.config/pluma/plugins/trailsave.pluma-plugin
[Pluma Plugin]
Loader=py... |
After printing out the plugin path from the source I found out that Pluma looks for plugins in ~/.local/share/pluma/plugins. The .pluma-plugin configuration file is correct however.
| How do I make Python plugins work in Pluma? |
1,351,250,142,000 |
When I open files by double-clicking a file with mouse I always get one additional "Unsaved Document X".. which is very annoying, because I have to close tham all, and click "Close without save" every time... This happens in dolphin, nautilus and krusader (those are the ones where I tried it, so I gues it's not becaus... |
Felrood from Arch Linux forums provided a solution and I would like to share it here and close this question.
Gedit seems to display data from stdin in a new "Unsaved document". For example:
echo "foobar" | gedit
What can be done is this:
right click the Kmenu button -> edit applications -> find gedit there
(for ... | Gedit opening an "Unsaved document" on opening files with mouse |
1,351,250,142,000 |
I don't like gedit and always use geany or vim or something else. Removing it from my current Debian testing install also removes the cinnamon-desktop-environment meta package because it depends on gedit. This meta package:
depends on all programs needed to have a fully fledged desktop environment. Install this if yo... |
Removing a program just because you don't use it shows a misguided sense of priorities. Disk space is cheap. Gedit takes less than 2MB of disk space. Even at SSD RAID-1 prices, that costs less than ½¢. At the minimum wage in my country, it takes less than 2s to earn that much. It'll take you far more than 2 seconds to... | Removing gedit without removing all of cinnamon-desktop-environment |
1,351,250,142,000 |
In regex plugin of gedit, I use a regex to match/search and another for substitution. In the matching regex, I only have one group. In the substitution regex, I use \1 to refer to the group, and I also like to add a zero right behind \1, but \10 will change to mean the 10th group in matching regex. So I was wondering ... |
Assuming that plugin uses the same syntax as the Python regexp engine: use \g<1>0 as the replacement text.
| How to match group 1 in a regex followed by a 0 rather than matching group 10 |
1,351,250,142,000 |
I want to remove unnecessary whitespace on my css file. I am using grep with the command as follows:
$ grep -rn "[[:space:]]$"
Surprisingly, it is returning a hit on every line in the file. I search for instances of \t\n, \r\n and \n but could not find anything. How do I go about identifying the invisible whitespace ... |
Don't be surprised that your regexps with a \n don't match: The \n is the line separator, it's not in the line. Every line in your file ends with \n-- by definition.* You'll never find a \n inside a line.
One possibility is that you're looking at a Windows file on Unix, and your mystery character is \r (NB not \r\n), ... | How to identify and remove invisible whitespace characters on gedit? |
1,351,250,142,000 |
I want to edit /etc/inittab in order to get a login prompt on the serial console once the system boots. By default, inittab file complains to be ro.
I tried both gksudo gedit /etc/inittab and sudo vi /etc/inittab and seemed to be properly configured. However, when I opened file after that with gedit, I saw no differen... |
Try this: Open terminal, then type su and type your root user password. After this:
vi /etc/inittab
In my case this works but I'm using CentOS.
| How to edit /etc/inittab? |
1,351,250,142,000 |
I'm using gedit 2.28.4, on Centos 6.4.
When I click on Edit > Preferences, I can't modify anything, as everything is grayed out.
Also, I could not re-size the preferences window to locate the 'Edit' button as suggested on other forums.
|
It turns out the gedit configuration files were missing completely. Reinstalling fixed the problem.
| gedit preferences grayed out |
1,351,250,142,000 |
I use gedit to modify/create files in my system, and sometimes I see that after editing, a duplicate file is created by the name of samename~
Just that ~ is extra. Why does this happen? Is there any significance of this file or is it okay if I delete it (I usually do)?
|
Some editors backs up the original file with a suffix, usually ~ but sometimes .bak, when saving the new file.
Vim, for example, does this if the backup option is enabled. With Vim, you may also modify the suffix used for the backup files:
set backup
set backupext=.bak
See also :help backup in Vim.
Refer to the docum... | Why is a duplicate file sometimes created after editing a file? [duplicate] |
1,351,250,142,000 |
I'm trying to save some work by editing multiple files with the same name located in different directories:
$ mkdir -p directory_{0..10}/results
How may I create files with the same name in all directories. For example,
$ vim/kwrite directory_*/results/output.txt
|
You almost have it with your second command. You did it correctly with the first, just use the same shell sequence expansion:
vim directory_{0..10}/results/output.txt
You should see something in the shell about opening 11 files. Then you can use vim to iterate through each one.
| Editing multiple files simultaneously with vim/gedit |
1,351,250,142,000 |
I do most of my coding in gedit, which highlights integers and other syntax. When I use an integer range in Ruby, represented as 0..3 for example, the integers are not properly highlighted and are instead the normal text colour. I checked out /usr/share/gtksourceview3.0/language-specs/ruby.lang, but, alas, the solutio... |
Well, right now I may suggest only 'brute force' solution. This task is all about knowing regular expressions.
Here it is.
First of all I decided to define a new regular expression that will match the whole range, instead of redefining decimal, but uses the same styles. There are 3 steps.
By the way, this is a guide a... | How can I syntax highlight Ruby range bounds in gtksourceview3.0? |
1,351,250,142,000 |
When ever I save a gedit file in a directory, two copies of it get saved with identical content. Ex: If the gedit file is named as file_name and saved in Home directory then when u ls the Home directory you get file_name and file_name~ in the list. When the file command is run against them I get ASCII text, with very ... |
These are backup files that gedit creates by default. You can disable this feature by going to
Preferences → Editor
and unchecking the line
Create a backup copy of files before saving
| Regarding identical copies of gedit files |
1,351,250,142,000 |
I'm often using gedit to print text documents. One thing I don't like is that it prints the full path to the document inside the page header, which sometimes overlaps what's in the top right corner; I'd like it to print the file name only.
Can that be done?
|
The code for this is
return g_file_get_parse_name (location);
in a function
gedit_document_get_uri_for_display:
that would need to be changed and gedit rebuilt or a PR created.
| Can I change how gedit prints its page header? |
1,351,250,142,000 |
I use the default gEdit on Cinnamon on Linux Mint, but I find when opening files from within it, I cannot navigate the open file dialog solely using the keyboard.
I hasn't been intuitive how I use tab and direction Keys
My config for curious readers in the future:
cat /etc/linuxmint/info
RELEASE=17.2
CODENAME=rafaela... |
I have found I can press Alt + Up/Down to navigate up and down the current file path location.
I haven't quite got this next part exactly correct, but if I want to navigate files within the selected path I can press Up or Down usually. Sometimes its a bit unexpected doing this and I use different direction keys or com... | Using open file dialog within gEdit using keyboard only |
1,435,262,063,000 |
I have a .txt file whith quite a long text content.
I noticed whenever I read the content up to a certain line and close the file, if I re-open the file later (right away, hours later, or days later), the file opens always displaying me the same region where I ended my previous reading and closed the file.
Do you have... |
Many text editors store your last cursor position in files you have edited. The information is often only stored for files you have saved with the editor, and different editors may behave differently in this regard. But it is not stored in the file you edited. It is stored somewhere else instead, because inside a plai... | Why text file always opens at the same point I closed it? |
1,435,262,063,000 |
This is the sequence of commands, gedit starts, but it cannot be killed from its process ID
$ gedit&
$ t=$!
$ echo $t
4824
$ kill $t
bash: kill: (4824) - No such process
It would work just fine for a sleep process, like
sleep 999&
[1] 4881
$ t=$!
$ echo $t
4881
$ kill $t
$ ps -p $t
[1] Terminated sleep... |
The gedit process is already terminated.
Remember how Windows applications mainly worked back in the Win16 days before Win32 came along and did away with it: where there were hInstance and hPrevInstance, attempting to run a second instance of many applications simply handed things over to the first instance, and this ... | can't kill gedit process from its PID |
1,435,262,063,000 |
Sometimes, after I’ve been editing a text file in Gedit, the letters clobber together like this:
Why is this? How can I stop it from happening?
|
Seems to be an effect of this bug: https://bugzilla.gnome.org/show_bug.cgi?id=127731
The bug is triggered when you have a very long line (something over 500k chars). You can stop it from happening by inserting some line breaks. If you really need the long line without line breaks then you will have to use another edit... | What is it that clobbers my letters together in Gedit? |
1,435,262,063,000 |
Pardon me if this is something that "everybody knows," but gedit (the gnome gui text editor) has a dependency on libbluray.
I've googled and read the release notes for gedit, with no luck, and I can't for the life of me think of a legitimate reason for this.
I'm using RHEL7 Workstation, but I suspect any gnome DE will... |
The gedit package doesn’t depend on libbluray directly; it depends on Gvfs, the virtual file system, and that can use libbluray to retrieve Blu-ray metadata. The RHEL package is built with this support in place, which is why you end up needing libbluray to install the gedit package (indirectly).
| Why does gedit need libbluray? |
1,435,262,063,000 |
I know how to make certain processes open up at start up but I'd really like to get gedit to open a number of files by default every time as well. It sometimes takes me a couple of minutes to find/remember all of them and this would make it a lot faster. Is this possible?
|
Just add this to your startup applications:
gedit "~/file 1" "~/Documents/file 2" "~/Desktop/file 3"
It passes the file paths as arguments to GEdit which causes GEdit to open these files.
| Can I get gedit to open on startup with a list of certain files? |
1,435,262,063,000 |
In gedit, Ctrl+D deletes a line.
Is there a shortcut for inserting/adding a line?
|
End+Enter will insert a line after the current one. You can use Home+Enter to insert before the current line
| Is there a shortcut in gedit to insert a line, i.e. the exact opposite of deleting a line? |
1,435,262,063,000 |
Say I want to remove all digits from a text file using
gedit 3.10.4
advanced_find 3.6.0
I have selected the Advanced Find/Replace plugin to support regular expressions out of an internet search. It seemed to stand out for simplicity, accessibility and users' endorsements. The version is claimed to be suitable for g... |
I am not fully aware of LibreOffice's internal syntax, but if you are talking about regex, as in regular expressions, you will have to use the digit symbol \d.
| Substitution with Regular Expressions in gedit |
1,435,262,063,000 |
I've been searching out for a plugin that could possibly wraps words with specified text.
For example I double click this word to highlight it :
word
and using a particular shortcut, it becomes as :
<b>word</b> or myFunction(word); or ...whatever depending what user defines.
I'm currently using Gedit v3. It would be... |
The "Snippets" plugin will do exactly that. Depending on your platform and version of Gedit, it should already be included, in which case you can simply enable it by going to Edit -> Preferences -> Plugins tab.
If it is not present, you may need to upgrade Gedit, as it is a default plugin distributed with Gedit and I... | Search plugin for wrapping words with text in Gedit v3 |
1,435,262,063,000 |
I am using a Linux beta in chromebook and gedit with plugins.
I want to make the gedit theme all dark. As you can see in the screenshot, I managed to change the theme, but the file browser and the terminal in Gedit won't turn dark. I already changed the color in Preferences → Font & Color.
|
LXAppearance has the least amount of dependencies and it configure GTK2/3 themes.
Other tools: https://wiki.archlinux.org/index.php/GTK#Configuration_tools
Configure manually by editing text files (does not always work):
https://wiki.archlinux.org/index.php/GTK#Basic_theme_configuration
As to what dark/black themes ar... | How do I apply darkTheme in gedit? |
1,435,262,063,000 |
I locked my Fedora18 computer (set to Polish). Later I couldn't log in (password was accepted, but I didn't see my desktop). I used pkill -KILL -u tymon command in root mode (Ctrl+Alt+f2).
After this, I didn't see (my native) Polish characters in gedit (I see only "bushes"). I don't why. I didn't install any update. ... |
Ok, I found the solution.
When I opened my file, there was set "Automatycznie wykryte" encoding, which means "automatically detected".
When I changed it to UTF-8, it works correctly. I don't know why, but it's a solution.
| Polish chars in gedit (Fedora 18) |
1,435,262,063,000 |
I have been trying to install a gedit plugin called RunC to compile C programs using the text editor.
Although the instructions tell me to use ubuntu 9 or 10 for this, I'm currently running Fedora 16. I thought that I would not have much problems, but after running the shell script using the sh command to install the ... |
I didn't manage to install it because RunC wasn't compatible with other distros. I confirmed this by installing Ubuntu 10, and it worked perfectly.
| Installing a gedit plugin on Fedora |
1,435,262,063,000 |
I'm installing and configuring the ssh in CentOs 8 with a virtual box machine.
I installed both libraries with following command:
sudo yum install openssh-server openssh-clients
Then I started the service with:
sudo systemctl enable sshd
sudo systemctl start sshd
sudo systemctl status sshd
And it's running normally... |
You're likely running Xwindows under your account, but are trying to open the gedit session as root with the sudo command. Try xhost local: to allow any user from the local host to access the display, then try the command again. If that works, you can refine it more to just allow root to access the display with xhost... | How to run sudo gedit without connection refusal? |
1,435,262,063,000 |
I am not sure if it is supported but cannot find it.
OS: Debian 8.5
|
It's supported by the code comment plugin (gedit-plugins in Debian). Make sure it's installed, then in the gedit preferences, enable "Code Comment" in the "Plugins" tab. Open a TeX or LaTeX document, select some text, and hit CtrlM to comment the corresponding lines. CtrlShiftM uncomments.
| How to comment out LaTeX code in Gedit? [closed] |
1,435,262,063,000 |
Note: I already know the answer, I'm only sharing my experience.
Some gedit plugins doesn't work on Lubuntu, the most notable is the Snippets one. I get the following error when I click on Tools->Manage Snippets:
Traceback (most recent call last):
File "/usr/lib/i386-linux-gnu/gedit/plugins/snippets/document.py", li... |
It seems gedit does havea very large number of missing required dependencies, that rise up when you try to use it on environments that are not Unity or GNOME.
To get rid of this particular problem, you have only to install:
sudo apt-get install python3-gi-cairo
Source: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug... | "Snippets" plugin doesn't work on gedit |
1,435,262,063,000 |
I try to use regex such as ^ to find the start of the line in the gedit editor in Ubuntu 22.04 but it doesn't work. Also for $ as the end of the line.
Other regular expressions such as \n,\d,\s work well
|
^ and $ work in gedit's Find and replace provided you tick the Regular expression box but gedit skips empty matches.
^$, ^ alone match an empty string so won't be replaced. x* matches 0 or more x's but gedit won't replace the occurrences matching 0 x's, so it's equivalent to using x+.
If you want to use Find and repl... | Start of the line with regex in Ubuntu 22.04's gedit text editor |
1,435,262,063,000 |
I was planning on building a current logging device with an Arduino, and tried starting off with the basic SD-card write example from the Arduino IDE sketchbook.
The Serial console showed no errors, so I assumed everything worked perfectly.
However... when I inserted the card in my computer (Ubuntu 18.04) and opened... |
As already shown in the edit, here's the answer:
executing od -c -tx1 DATALOG.TXT | head -1
gave me this:
0000000 \r \n \r \n \r \n \r \n \r \n \r \n \r \n \r \n
This hinted me that the file might have a bunch of newlines at the beginning, with the contents trailing.
This turned out to be the case.... | cat shows file contents, gedit and vim show blank file |
1,435,262,063,000 |
I am reading a tutorial that wants me to place a script file called script.sh into a folder called /etc/profile.d/. However, when I try to save the script.sh file in that directory, the gedit tool gives me an error stating that I do not have privileges to save in that folder. So I saved script.sh on the desktop temp... |
If you have the sudo package try gksudo nautilus, otherwise use sudo mv -v /home/username/Desktop/script.sh /etc/profile.d/script.sh For more, try man mv
sudo elevates the command following it temporarily to perform tasks like you describred.
| moving a file to a folder with root privileges in CentOS 7 |
1,359,459,458,000 |
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 ... |
If it has to be portable to a range of Unices, you'd have to stick to POSIX sh. And AFAIU there you just have no choice but rolling argument handling by hand.
| getopt, getopts or manual parsing - what to use when I want to support both short and long options? |
1,359,459,458,000 |
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?
|
Use getopts.
It is fairly portable as it is in the POSIX spec. Unfortunately it doesn't support long options.
See also:
the Small getopts tutorial (in the Bash Hackers wiki)
another question on StackOverflow.
If you only need short options, typical usage pattern for getopts (using non-silent error reporting) is:
# ... | How do I handle switches in a shell script? |
1,359,459,458,000 |
I have this code -
#getoptDemo.sh
usage()
{
echo "usage: <command> options:<w|l|h>"
}
while getopts wlh: option
do
case $option in
(w)
name='1';;
(l)
name='2';;
(h)
name='3';;
(*)
u... |
When you run this script without any options, getopt will return false, so it won't enter the loop at all. It will just drop down to the print - is this ksh/zsh?
If you must have an option, you're best bet is to test $name after the loop.
if [ -z "$name" ]
then
usage
exit
fi
But make sure $name was empty before... | How can I detect that no options were passed with getopts? |
1,359,459,458,000 |
In option string when using getopts, from http://wiki.bash-hackers.org/howto/getopts_tutorial
If the very first character of the option-string is a : (colon), which would normally be nonsense because there's no
option letter preceding it, getopts switches to " silent error reporting mode". In productive scripts... |
If the very first character of optstring is a colon, getopts will not produce any diagnostic messages for missing option arguments or invalid options.
This could be useful if you really need to have more control over the diagnostic messages produced by your script or if you simply don't want anything to appear on the ... | What is the purpose of the very first character of the option-string of getopts being a : (colon)? |
1,359,459,458,000 |
I have a bash script as below in a file nepleaks_upd.sh, that I want to run as ./nepleaks_upd.sh bootstrap --branch off. Couldn't make it to take --branch , but what it works with is ./nepleaks_upd.sh bootstrap -b off.
usage() { echo "Usage: $0 [prepare | up | down] [-b <on/off>]" 1>&2; exit 1; } ... |
getopts starts parsing at the first argument and stops at the first non-option arguments. That's the standard convention — some GNU utilities accept options after arguments, but the normal thing is that in somecommand foo -bar qux, -bar is not parsed as an option.
If you want to start parsing options after bootstrap, ... | Using getopts to parse options after a non-option argument |
1,359,459,458,000 |
In below code when I give option r then getopts requires one arguments:
while getopts ":hr::l:" opt; do
case $opt in
r ) echo "Run Numbers - argument = $OPTARG " ;;
l ) echo "Latency range - argument = $OPTARG" ;;
h ) helptext
graceful_exit ;;
* ) usage
clean... |
You cannot pass two arguments with single option using getopts.
I recommend the following alternatives:
Put quotes around multiple arguments
In this case getopts will treat them as one argument, but you will be able to split it later on. You can even put all arguments in the array at once:
#!/bin/bash
while getopt... | Provide two arguments to one option using getopts |
1,359,459,458,000 |
I defined the function f in Bash based on the example here (under "An option with an argument"):
f () {
while getopts ":a:" opt; do
case $opt in
a)
echo "-a was triggered, Parameter: $OPTARG" >&2
;;
\?)
echo "Invalid option: -$OPTARG" >&2
return 1
;;
:)
... |
bash getopts use an environment variable OPTIND to keep track the last option argument processed. The fact that OPTIND was not automatically reset each time you called getopts in the same shell session, only when the shell was invoked. So from second time you called getopts with the same arguments in the same session,... | Bash function with `getopts` only works the first time it's run |
1,359,459,458,000 |
I am working with a pretty simple bash script, but I am facing a problem which I can't resolve:
I have myscript.sh with three parameters, -u, -h, and -p.
Both -u and -h are mandatory, needed for the script to run.
What I would like to do is, if myscript.sh -u User1 and nothing more it should terminate with exit 1.
I w... |
Maybe something like this?
#!/bin/bash
unset -v host
unset -v port
unset -v user
while getopts h:p:u: opt; do
case $opt in
h) host=$OPTARG ;;
p) port=$OPTARG ;;
u) user=$OPTARG ;;
*)
echo 'Error in command line parsing' >... | Bash getopts, mandatory arguments |
1,359,459,458,000 |
As I was looking this answer https://stackoverflow.com/a/11065196/4706711 in order to figure out on how to use parameters like --something or -s some questions rised regarding the answer's script :
#!/bin/bash
TEMP=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
-n 'example.bash' -- "$@"`
if [ $? != 0 ] ; the... |
One of the many things that getopt does while parsing options is to rearrange the arguments, so that non-option arguments come last, and combined short options are split up. From man getopt:
Output is generated for each element described in the previous section.
Output is done in the same order as the elements are spe... | Bash: Why is eval and shift used in a script that parses command line arguments? |
1,359,459,458,000 |
I use getopts to parse arguments in bash scripts as
while getopts ":hd:" opt; do
case $opt in
d ) echo "directory = $OPTARG"; mydir="$OPTARG"; shift $((OPTIND-1)); OPTIND=1 ;;
h ) helptext
graceful_exit ;;
* ) usage
clean_up
exit 1
esac
done
exeparams="$*"
exeparams will hold any un... |
How about:
# ... getopts processing ...
[[ $1 = "--" ]] && shift
exeparams=("$@")
Note, you should use an array to hold the parameters. That will properly handle any arguments containing whitespace. Dereference the array with "${exeparams[@]}"
| How to deal with end of options -- in getopts |
1,359,459,458,000 |
The Linux foundation list of standard utilities includes getopts but not getopt. Similar for the Open Group list of Posix utilities.
Meanwhile, Wikipedia's list of standard Unix Commands includes getopt but not getopts. Similarly, the Windows Subsystem for Linux (based on Ubuntu based on Debian) also includes getopt ... |
which is the wrong tool. getopts is usually also a builtin:
Since getopts affects the current shell execution environment, it is
generally provided as a shell regular built-in.
~ for sh in dash ksh bash zsh; do "$sh" -c 'printf "%s in %s\n" "$(type getopts)" "$0"'; done
getopts is a shell builtin in dash
getopts i... | Which is the more standard package, getopt or getopts (with an "s")? |
1,359,459,458,000 |
I'm trying to build up a shell script that accepts various options and getopts seems like a good solution as it can handle the variable ordering of the options and arguments (I think!).
I'll only be using short options and each short options will require a corresponding value eg: ./command.sh -a arga -g argg -b argb b... |
When you call your second script (I saved it as getoptit) with:
getoptit -d -h
This will print:
MYSQL_HOST='' MYSQL_USER='' MYSQL_PASS='' BACKUP_DIR='-h' Additionals:
So BACKUP_DIR is set, and you are testing with if [ ! "$BACKUP_DIR" ]; then if it is not set, so it is normal that the code inside of it is not tr... | bash getopts, short options only, all require values, own validation |
1,359,459,458,000 |
When parsing command line arguments with GNU getopt command, how do I (if possible) do recognize -? as another option? Is there a way to escape it in the opstring?
|
The GNU getopt command uses the GNU getopt() library function to
do the parsing of the arguments and options.
The man page getopt(3) states:
If getopt() does not recognize an option character, it prints an error
message to stderr, stores the character in optopt, and returns ?.
The calling program may prevent the ... | How to specify -? option with GNU getopt |
1,359,459,458,000 |
I'm using getopts for all of my scripts that require advanced option parsing, and It's worked great with dash. I'm familiar with the standard basic getopts usage, consisting of [-x] and [-x OPTION].
Is it possible to parse options like this?
dash_script.sh FILE -x -z -o OPTION
## Or the inverse?
dash_script.sh -... |
Script arguments usually come after options. Take a look at any other commands such as cp or ls and you will see that this is the case.
So, to handle:
dash_script.sh -x -z -o OPTION FILE
you can use getopts as shown below:
while getopts xzo: option
do
case "$option" in
x) echo "x";;
z) echo "z";;
... | Getopts option processing, Is it possible to add a non hyphenated [FILE]? |
1,359,459,458,000 |
Problem
I have a script that accepts a few different (optional) command line arguments. For one particular argument, I'm getting the value "less" appear but I don't know why.
Bash Code
while getopts ":d:f:p:e:" o; do
case "${o}" in
d)
SDOMAIN=${OPTARG}
;;
f)
FROM=... |
Your script never sets PAGER, but that variable is likely exported from your current environment; check with declare -p PAGER.
I would recommend using a different variable name inside your script; this is why there's a general recommendation against using upper-case variables as your own.
| bash script: incorrect argument value being set |
1,359,459,458,000 |
By convention -- signals that there is no more options after it.
It seems to me that when using getopts with case clause, -) pattern subclause doesn't match --. So what is the behavior of getopts when it meets --? Does it treat -- as an option, a nonoption argument, or neither? Thanks.
|
The behaviour is that it stops parsing the command line and leaves the rest of the arguments as is. The -- itself is removed (or rather $OPTIND will indicate that it was processed but $opt in the code below will never be -, and if you shift "$(( OPTIND - 1 ))" as one usually does, you'll never see it).
Example:
#!/bin... | What is the behavior of `getopts` when it meets `--`? |
1,359,459,458,000 |
I am trying to run the following script using getopts to parse the options but it does not seem to work:
#!/bin/bash
set -x
echo $@
while getopts "rf" opt
do
case "${opt}" in
r)
ropt=${OPTARG}
;;
f)
fopt=${OPTARG}
;;
esac
done
shift $((OPTIND -1))
echo $fopt $ropt
The out... |
You expect your options to take option-arguments, but you don't let getopts know about this.
You should use
while getopts "r:f:" opt; do ...; done
i.e., each option that takes an argument should have : after it in the argument string to getopts.
You'll probably also want a default case branch at the end to handle in... | getopts does not seem to work |
1,359,459,458,000 |
I am new to bash scripting and I am trying to write a script with getopts so that when script.sh -sp is is invoked the URL and column and row count is printed out. And when script.sh -r option is invoked only the file type is printed.
Script :
#!/bin/bash
#define the URL
URL='https://github.com/RamiKrispin/coronavir... |
getopts only supports single-character option names, and supports clustering: -sp is equivalent to passing -s and -p separately if -s doesn't take an argument, and it's the option -s with the argument p if -s takes an argument. This is the normal convention on Unix-like systems: after a single dash -, each character i... | How to use getopts in bash |
1,359,459,458,000 |
I ran into an interesting scenario last night and, so far, my google foo has been unable to find a work around. I have a script that supports a number of arguments. A user (damn those users) didn't specify an argument for an option and the results were ... unexpected.
The code:
while getopts "a:c:d:De:rs:" arg
do
... |
I would use getopt instead of getopts:
#!/usr/bin/env bash
OPT=$(getopt \
--options a:c:d:De:rs: \
--name "$0" \
-- "$@"
)
if [ $? -ne 0 ]; then
echo You are doing it wrong!
exit 1
fi
eval set -- "${OPT}"
while true; do
case "$1" in
-a) app=${2}; shift 2;;
-c) cmd=${2}; sh... | bash case && extra OPTARG |
1,359,459,458,000 |
I'm trying to create a script that has an option that will contain arbitrary text (including spaces) surrounded by quotes and this is proving difficult to search for and implement.
Basically the behavior I would like to have is docker_build_image.sh -i "image" -v 2.0 --options "--build-arg ARG=value", this will be a h... |
Given you seem to be using the "enhanced" getopt (from util-linux or Busybox), just handle options like you handle the others that take an argument (image and version). I.e. add the colon marking a mandatory argument to the option string that goes to getopt, and pick the value off of $2.
I think the error you get come... | How to parse Command Line Arguments with arbitrary string |
1,359,459,458,000 |
I have the following commands in my script:
set -- `getopt -q agvc:l:t:i: "$@"`
...
while [ -n "$1" ]
do
-i) TIME_GAP_BOOT=$2
shift ;;
...
sleep $TIME_GAP_BOOT
When invoking the script with -i 2, I get the error
sleep: invalid time interval `\'2\''
What am I doing wrong? How do I correctly format the argum... |
The bash builtin getopts is a lot easier to use. If you're using bash, you should use it instead of getopt.
GNU getopt is designed to work with arguments which have whitespace and other metacharacters in them. In order to do that, it produces a result string with bash-style quotes (or csh-style quotes, depending on th... | How do I fix the argument received from getopt? |
1,359,459,458,000 |
I am trying to call a function in a while loop passing some arguments. However, getopts can only get the arguments for the first call.
Here's a minimal example:
function add_all_external_services() {
env | sed -n "s/^EXTERNAL_SERVICE_OPTIONS_\(.*\)$/\1/p" > options
while read -r line
do
key="${line%%=*}"
... |
This is because you are not resetting OPTIND. According to the manual:
Each time it is invoked, getopts places the next option in the shell variable name, initializing name if it does not exist, and the index of the next argument to be processed into the variable OPTIND. OPTIND is initialized to 1 each time the shel... | getopts gets no arguments when function is called inside while loop |
1,359,459,458,000 |
According to several sources, the UNIX utility guidelines specify that operands should always be processed after options:
utility_name[OPTIONS][operands...]
Some older UNIX utilities are known to not follow these conventions quite so, e.g, find, but newer and well-established utilities do too break the rules without ... |
The normal convention is that arguments always follow options. The first non-option (the first string on the command line that does not start with -) terminates the options and begins the arguments.
Some tools, notably the build tools (compilers, linkers), have always gone against this convention. Another example that... | Why do some utilities parse operands before options? |
1,359,459,458,000 |
I want to parse multiple arguments using getopts in a bash script using the code below.
while getopts b:B:m:M:T flag
do
case "${flag}" in
b) rbmin=${OPTARG};;
B) rbmax=${OPTARG};;
m) mbmin=${OPTARG};;
M) mbmax=${OPTARG};;
T) sigType=${OPTARG};;
esac
done
echo $rbmin,$rbm... |
You seem to be missing the : after T in the option string given to getopts. This : would indicate that -T takes an option-argument.
Without the :, -T would be an option with no argument, and your invocation would leave sig as an operand at the end of the command line rather than as an option-argument.
while getopts b... | getopts for more than 4 parser arguments |
1,359,459,458,000 |
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-long-flag)
params="$params -m";;
--another-flag)
params="$params -a";;
"-?"|--help)
usage
e... |
You don't need to use a bash array here (but do so if it feels better).
Here's how to do it for /bin/sh:
#!/bin/sh
for arg do
shift
case "$arg" in
--my-long-flag)
set -- "$@" -m ;;
--another-flag)
set -- "$@" -a ;;
"-?"|--help)
usage
exi... | Can a bash array be used in place of eval set -- "$params"? |
1,359,459,458,000 |
I am writing a script which can choose a file and print specific content. For example,
san#./script.sh
Expected Usage : ./script.sh --file1 --dns
(Here it checks for file1, search for dns name and prints. Basically there are sub-parameters under a parameter)
I tried for single parameter/Option as below :
options=$@
... |
This is a version that is more convenient to use than the first
one I gave here, in particular it avoids duplicated code for
equivalent long and short options. It should handle anything you
ever want for options:
short options (-q), long options (--quiet), options with
arguments, accumulated short options (-qlfinput
i... | Including sub-parameters in help options to execute wisely without getopt or getopts? |
1,359,459,458,000 |
I am attempting to do copy a file (or rename a file) by running the script with flags/parameters to give both the source and the destination file name:
#!/bin/bash/
while getopts s:d flag
do
case "${flag}" in
s) copy_source=${OPTARG};;
d) copy_dest=${OPTARG};;
esac
done... |
You are missing the mandatory : after the d in your while getopts line if the -d is to accept a parameter. Therefore your copy_dest is empty, and hence cp complains about the "missing operand". If you add "debug" lines such as
echo "Source parameter: $copy_source"
echo "Destination parameter: $copy_dest"
after your l... | Using command-line parameters as destination for cp and mv in bash script |
1,359,459,458,000 |
Considering:
#!/bin/sh
while getopts ":h" o; do
case "$o" in
h )
"Usage:
sh $(basename "$0") -h Displays help message
sh $(basename "$0") arg Outputs ...
where:
-h help option
arg argument."
exit 0
;;
\? )
echo "Invalid option -$OPTARG" 1>&2
exit 1
... |
You seemed to have missed printing the message but rather passing the whole string as a command to run. Add an echo before the string
case "$o" in
h )
echo "Usage:
sh $(basename "$0") -h Displays help message
sh $(basename "$0") arg Outputs ...
where:
-h help option
arg argument."
exi... | Unexpected behavior from getopts |
1,359,459,458,000 |
I want to write a shell script which will take some arguments with some options and print that arguments. Suppose the name of that script is abc.ksh. Usage of that script is -
./abc.ksh -[a <arg>|b <arg>|c|d] <some_string>
Now I write a shell script which will take options and arguments
#!/bin/ksh
# Default Values
... |
It is typical for programs to force the "some_string" part to be the last argument so that .abc.ksh "some_string" -a "sample text" is an error. If you do this, then after parsing the options, $OPTIND holds the index to the last argument (the "some_string" part).
If that is not acceptable, then you can check at the beg... | How to catch optioned and non optioned arguments correctly? |
1,359,459,458,000 |
I have the following bash function:
lscf() {
while getopts f:d: opt ; do
case $opt in
f) file="$OPTARG" ;;
d) days="$OPTARG" ;;
esac
done
echo file is $file
echo days is $days
}
Running this with arguments does not output any values. Only after running the function without arguments, and ... |
Though I can't reproduce the initial run of the function that you have in your question, you should reset OPTIND to 1 in your function to be able to process the function's command line in repeated invocations of it.
From the bash manual:
OPTIND is initialized to
1 each time the shell or a shell script... | bash function arguments strange behaviour |
1,359,459,458,000 |
I have a shell script testShell.sh which uses getopts as below:
#!/bin/bash
while getopts ":j:e:" option; do
case "$option" in
j) MYHOSTNAME=$OPTARG ;;
e) SCRIPT_PATH=$OPTARG ;;
*) ;;
esac
done
echo "j=$MYHOSTNAME"
echo "e=$SCRIPT_PATH"
shift $((OPTIND - 1))
echo "remaining=$@"
When ... |
After posting it on 3 forums and searching everywhere... eventually I tried the following and it worked...
testShell.sh -jvalue1 -evalue4 -- -Djvalue3 -pvalue2
Notice
--
after -evalue4
And the output was
j=value1
e=value4
remaining=-Djvalue3 -pvalue2
I believe -- asks getopts to stop processing options.
| how to make getopts just read the first character post `-` |
1,359,459,458,000 |
So I am writing a script that mixes options with arguments with options that don't. From research I have found that getopts is the best way to do this, and so far it has been simple to figure out and setup. The problem I am having is figuring out how to set this up so that if no options or arguments are supplied, for ... |
You can use any of the following to run commands when $1 is empty:
[[ ! $1 ]] && { COMMANDS; }
[[ $1 ]] || { COMMANDS; }
[[ -z $1 ]] && { COMMANDS; }
[[ -n $1 ]] || { COMMANDS; }
Also, you don't need to quote the expansion in this particular example, as no word splitting is performed.
If you're wanting to check if th... | How to run a specified codeblock with getopts when no options or arguments are supplied? |
1,359,459,458,000 |
I have copied code from tutorialspoint's getopt article and got the following script to work (sort of):
##argument_script.sh
VARS=`getopt -o i::o:: --long input::,output:: -- "$@"`
eval set -- "$VARS"
# extract options and their arguments into variables.
while true ; do
case "$1" in
-i|--input)
... |
The behavior you describe is because you have an extra : in your getopt. Just change your getopt line to this and it will work:
VARS=`getopt -o i:o: --long input:,output: -- "$@"`
However, this is a very, very convoluted way of writing your script. Here is a simpler version (also correcting some bad practices like ca... | bash script with optional input arguments using getopt |
1,359,459,458,000 |
I have a script where I've implemented switches using getopts. However, I'm having trouble referencing the next argument.
My script is for backporting a backup of our website on a local development environment. I've added a -p switch to run some post-deploy steps. Here's my syntax:
backport -p /path/to/website_backup... |
I can only blame myself for poor communication, but Kusalananda has given the answer I was looking for in a comment.
After using getopts to parse switches
while getopts "p" opt; do
case $opt in
p) p_post_deploy=true ;;
esac
done
this line
shift "$((OPTIND - 1))"
will remove all switches from the list of argu... | Parsing script arguments after getopts |
1,359,459,458,000 |
I have two scripts ins.sh and variable.sh. variables.sh holds various key-value pairs.
ins.sh
#!/usr/bin/env bash
set -e # Exit upon error
# This script generates a 64-bit system
source variables.sh
# Parse options
while getopts ":t:" opt; do
case $opt in
t )
if [ $OPTARG = TRUE ] || [ $OPTA... |
Replace:
sed -i "s/*.MAKE_TESTS=.*/MAKE_TESTS=${OPTARG}/" variables.sh
with:
sed -i "s/.*MAKE_TESTS=.*/MAKE_TESTS=${OPTARG}/" variables.sh
.* means zero or more of any character. By contrast, the meaning of *. may likely vary from one implementation of sed to another. In GNU sed, it means a literal star, *, foll... | sed whole string replacement not working |
1,359,459,458,000 |
I'm trying to use the ksh built-in getopts to manage runtime options for my ksh code.
I keep on getting the error: "unknown option argument value" when using an option that requires and argument.
Here's the offending code:
$ cat usage.sh
#!/bin/ksh
#set -xv
USAGE=$'[-?\n@(#)$Id: '"script_name"
USAGE+=$'\n'"script_ver... |
Posting this as memo, the following code works as intended:
#!/bin/ksh
#set -xv
USAGE=$'[-?\n@(#)$Id: '"script_name"
USAGE+=$'\n'"script_version"$' $\n]'
USAGE+="[m:mode?Sets notification mode.]:[mode:=ALL]"
USAGE+="{[S:SMS?SMS notification][M:MAIL?EMAIL notification][A:ALL?EMAIL and SMS notification]}"
while getopt... | KSH - built-in getopts unknown option argument value |
1,359,459,458,000 |
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), executing below commands:
OPTIND=1 && getopts ":n:" opt "-n 1" && echo "OPTARG: '$OPTARG'"
and it echos:
OPTARG: ' 1'
Howeve... |
You should just leave out the double quotes around "-n -1", as that is what preserves the space before the 1:
OPTIND=1 && getopts ":n:" opt -n 1 && echo "OPTARG: '$OPTARG'"
gives:
OPTARG: '1'
| Strange leading whitespace in OPTARG when using getopts |
1,359,459,458,000 |
for instance, gcc accepts the input file without any flag and the output file with the -o flag in:
gcc input.c -o output.out
or
gcc -o output.out input.c
I am creating a random password generator bash script, the user should be able to specify the number of special chars, lowercase chars and uppercase chars using the ... |
getopts stops parsing the argument list as soon as it reaches a non-option argument. That is, it returns success as it iterates left-to-right over the option arguments, then returns failure on the first non-option. So the proper use case is put options and their arguments on the command line before any non-option arg... | How to mix plain arguments with flagged arguments in bash scripting? |
1,359,459,458,000 |
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 $OPTARG" >&2
;;
f)
echo "-f was triggered with $OPTARG" >&2
;;
\?)
echo "Invalid option: -$OPTAR... |
You have told getopts that the -d option should take an argument, and in the command line you use -d -f myformat which clearly (?) says "-f is the argument I'm giving to the -d option".
This is not an error in the code, but in the usage of the script on the command line.
Your code needs to verify that the option-argum... | how to properly parse shell script flags and arguments using getopts |
1,359,459,458,000 |
Hey is there any difference between $OPTIND and $#?
Is there a certain reason for that you use $OPTIND with getopts, not $#?
|
$OPTIND indicates how far you have progressed through parsing the parameter list (i.e., for options), while $# is simply the number of parameters. They are not really related, because $OPTIND changes, while $# does not (unless you use shift).
The POSIX description of getopts goes into some detail.
| Difference between $OPTIND and $# |
1,359,459,458,000 |
If getopts is a bash function, by my understanding, you need to pass $@ - the whole arguments to getopts to let the function know what kind of arguments you have in order to proceed, right?
It seems to me that you don't need it, so how the getopts get to know what arguments I have in the current scope? Does it have a ... |
getopts is a shell built-in, so it can reference $@ directly. It also sets the shell variables OPTARG and OPTIND. (Note that inside a function, getopts will reference that function's $@ rather than the global arguments. You should localise OPTIND if you want a repeatable (odempotent) function call.)
The synopsis (summ... | How bash getopts knows what arguments the call has |
1,359,459,458,000 |
This is my assignment. The task is to output n longest lines from the input file(s). If there is no argument for n, the the default of value n is 5. If there is no files in the parameter, the standard input is used. If there are at least 2 files, output the name files. The output lines should be in the same order as i... |
Your -n option takes an argument, so you need getopts 'n:' arg.
The option argument is found in $OPTARG.
Don't touch OPTIND in the while getopts loop.
After the loop, shift "$(( OPTIND - 1 ))". This leaves the filenames in the positional parameters.
That is,
#!/bin/sh
level=5
while getopts 'n:' arg; do
case $arg... | How to correctly identify the order of parameters? |
1,507,439,499,000 |
I'm trying to get a script to:
set a variable with -q option
show help for -h option, and
fail for other options -*, but allow positional arguments
Here is the getopts snippet I'm using:
while getopts qh opt; do
case "${opt}" in
q)
quiet="true"
;;
h)
usage
... |
The shift command is misplaced. It should be outside of the while loop. Try:
while getopts :qh opt; do
case "${opt}" in
q)
quiet="true"
;;
h)
usage
exit 1
;;
\?)
echo "unrecognized option -- ${OPTARG}"
exi... | getopts does not match the second argument |
1,507,439,499,000 |
I'm coding a script that goes and searches for files on a remote server and transfers them back to my local computer. I want to be able to do a dry run first, so I know which files I'm bringing back.
I'm currently using a mix of getopts and output redirection from some code I found here.
It seems to me, through my r... |
I don't know zsh, but:
1) first ensure that all your "conversational" print statements go to stderr, NOT to stdout, such as:
print -Pn "\n%S%11F%{Initiating Dry-Run%}%s%f" >&2
and many others.
2) Instead of executing your scp statements, printf them to stdout, such as:
printf 'scp -qp mcdodyla@falcon1:"%s" "%s"\n' "$... | Proper way to code dry run option without having to repeat myself? |
1,507,439,499,000 |
I have a script that starts with getopts and looks as follows:
USAGE() { echo -e "Usage: bash $0 [-w <in-dir>] [-o <out-dir>] [-c <template1>] [-t <template2>] \n" 1>&2; exit 1; }
if (($# == 0))
then
USAGE
fi
while getopts ":w:o:c:t:h" opt
do
case $opt in
w ) BIGWIGS=$OPTARG
;;
o ) OU... |
The getopts utility does not know about mandatory options, only about what options are allowed (and what options out of these should take an option argument). If you want to enforce mandatory options, you would have to do so with your own tests in or after the option parsing loop.
The getopts utility does not do this ... | Handling unused getopts argument (are options not mandatory?) |
1,507,439,499,000 |
I am working on a a script that need to take two script arguments and use them as variables in the script. I couldn't get this working and unable to find out what I am doing wrong. I see the issue is the second argument, as I see in some of my tests(as mentioned in the bottom of this post) it is not being read.
Here i... |
$_env is unset due to how you pass arguments to getopts.
You need to add a colon after the e to tell getopts the option takes an argument.
while getopts "p:e:" op
^
mandatory here
Check:
help getopts | less
| script arguments in bash |
1,507,439,499,000 |
I have a script to get ldap user name, email and mobile number:
#!/bin/bash
echo -n "Enter Unix id > "
read UNIXID
ldapsearch -x "(cn=$UNIXID)" | awk '/givenName/||/mobile/||/mail/'
Here is the output of the script:
#./lsearch
Enter Unix id > in15004
givenName: Mr. Xyz
mail: [email protected]
mobile: 9xxxxxxxx1
Now ... |
If you want to use getopts (noted the "s") to get the command line arguments you can do something like
while getopts "i:n:e:" OPT; do
case "$OPT" in
i)
# do stuff with the i option
ID="$OPTARG"
;;
n)
# do stuff with the n option
;;
... | Command line options with argument in shell script |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.