Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

Raspberry Pi OS • Re: Tip: Use .bash_history, Skip SSH for RPi OS Lite Commands

$
0
0
isn't it easier to just to type in the command and try it, then it gets inserted in to bash_history automatically?

Manually typing lengthy and complex commands can be time-consuming and prone to errors. For example, consider the following command (note its considerable length):

Code:

sudo apt-get install gnome-core rpi-chromium-mods celluloid gnome-tweaks  yaru-theme-gnome-shell yaru-theme-gtk yaru-theme-icon yaru-theme-sound yaru-theme-unity fonts-ubuntu fonts-ubuntu-title fonts-ubuntu-console gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-alsa gstreamer1.0-pulseaudio gstreamer1.0-xsudo apt-get install -y dbus-x11 nautilus && sudo bash -c 'echo -e "[Desktop Entry]\nType=Application\nName=Nautilus Admin\nExec=/usr/share/applications/nautilus.sh\nIcon=system-file-manager\nTerminal=false\nComment=Manage folders and files as administrator" > /usr/share/applications/nautilus.desktop && echo -e "#!/bin/bash\n#sudo chmod +x ...\npkexec env DISPLAY=\$DISPLAY XAUTHORITY=\$XAUTHORITY nautilus /home/" > /usr/share/applications/nautilus.sh && chmod +x /usr/share/applications/nautilus.sh'
This command is extremely long, and typing it manually is not only tedious but also increases the chance of errors. Let’s be honest—this is not something you'd want to type out by hand. 😉

By preloading this command into the .bash_history file, you can easily execute it using the Up Arrow key, saving time and avoiding the risk of mistakes. This method simplifies the execution of such lengthy commands, especially for tasks that need to be repeated or slightly modified.
But you've still got to type it in to preload it into your bash history so your argument is ludicrous. Especially as you could still make a mistake and not notice until you run it.

If a long command is used frequently it's better to create an alias for it (in one of .profile, .bashrc, or .bash_aliases). Your .bash_history is not intended to be manipulated in this way and gets truncated periodically so your command will fall out of it.

And depending on where it is in your history it's going to be more than one press of the "up" key to find it.

Or stick it in a file and run it with bash < some-file

Statistics: Posted by thagrol — Sat Nov 23, 2024 4:06 pm



Viewing all articles
Browse latest Browse all 8026

Trending Articles