Actually no, if we return -1 in bash, it will be interpreted as 255 per https://tldp.org/LDP/abs/html/exitcodes.html
if I can go back in time, I would never return exit code -1 for a failure in Linux. 1 would be ideal in this case.
Let write a simple bash script test – to copy non-existent file
the execution will fail and exit status code is 1 as expected so let’s modify this script and return the exit status code to -1.
Since we alter our script by checking if exit code is not zero, we instead return -1. As a result, bash interprets it as out of range since exit takes only integer args in the range 0 – 255 and therefore interprets it as 255 instead of -1.
I am a backend engineer and we are working on a new Linux Project. We have UI UX team with us which they mainly work on UI UX front end. Once they are done with their UI UX work, they handed it over to us – backend engineers to integrate UI UX stuff with the backend Linux daemon service which runs in the background and/or at startup. After the integration, we found few issues with UI UX stuff mainly filtering as we have many options for end user to filter in the front end and I was also assigned to fix them which I did. Through working on fixing them, I came across JS code which uses IndexOf to find a match and I would have thought IndexOf(“”) empty string should yield -1 but it does not and instead it yields 0 and I also wonder what would be yielded in C#. I did a quick console app in .NET to test. And as a result, C# behaves the same way – returns 0.
Reports the zero-based index of the first occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance.
But not too quick, if we go further below here it stated:
The zero-based index position of value from the start of the current instance if that string is found, or -1 if it is not. If value is Empty, the return value is startIndex.
I have VS 2019 enterprise edition and its attach to process took very long time to show up and that have impacted my productivity drastically. So far I have been complaining McAfee Anti-virus for this issue but turned out it was not due to McAfee at all.
Once I deselected Python Development workload in the VS installer screen below, it seems to resolve the issue and attach to process screen above pops up quicker.
A while back probably couple years ago I wrote bash scripts to backup and restore MySQL db on Linux platform mainly for debugging and/or troubleshooting purposes and here they are:
########################################
### backup.sh Backup mysql db script ###
########################################
#!/bin/bash
userhome=$(eval echo "~$USER")
echo "Executing under $USER context"
echo "Enter db username: "
read -s USER
echo "Enter db password: "
read -s PASS
read -p "Enter database name: " DBNAME
### Backing up database ###
mysqldump -u$USER -p"$PASS" $DBNAME > $userhome/$DBNAME.sql
echo "---------------------------------------------------------------------------------"
echo "if no error, $DBNAME backup will be saved to $userhome/$DBNAME.sql"
echo "---------------------------------------------------------------------------------"
##########################################
### restore.sh restore mysql db script ###
##########################################
#!/bin/bash
userhome=$(eval echo "~$USER")
echo "Executing under $USER context"
echo "Enter dba username: "
read -s USER
echo "Enter dba password: "
read -s PASS
read -p "Enter database name: " DBNAME
read -p "Enter database backup location (.sql): " DBBACKUPSQL
### restore backup database ###
mysql -u$USER -p"$PASS" -e "drop database $DBNAME;"
mysql -u$USER -p"$PASS" -e "create database $DBNAME;"
mysql -u$USER -p"$PASS" $DBNAME < $DBBACKUPSQL
echo "---------------------------------------------------------------------------------"
echo "if no error, $DBBACKUPSQL backup has been restored"
echo "---------------------------------------------------------------------------------"
To backup, at terminal execute backup.sh
# bash backup.sh
it will prompt you for the database username and password and db.sql will be saved to the home directory of the user you use to execute this script.
To restore, at the terminal execute restore.sh
it will prompt you for the database admin username, password, and the backup script .sql location.
Sometime we might want to login to CLI (Command Line Interface) where Desktop won’t be available and only terminal is accessible. Most of the time the reason we login under CLIs is that it is lightweight so it is running faster than running with Desktop. So how do we boot Centos or Oracle Linux into CLIs?
To switch from Desktop to CLI, execute below command:
# sudo systemctl set-default multi-user.target
# sudo reboot
To switch from CLI back to Desktop, execute below command:
# sudo systemctl set-default graphical.target
# sudo reboot
Now under CLIs, we do not have Desktop (Windows system) available so how do we launch GUI App (X app) in CLI environment then? Yes we can please follow:
Example, how to we launch GUI App like Google Chrome under CLIs (Desktopless).
We need to use startx to launch it under X session (so-called X windows system or simply Graphical session)
you can read more about startx here https://www.x.org/releases/X11R7.5/doc/man/man1/startx.1.html
startx [ [ client ] options ... ] [ -- [ server ] [ display ] options ... ]
In our case, client is going to be the Google Chrome and please note that startx requires the full path of the client, Google Chrome.
To locate the full path of Google Chrome, execute below command:
#which google-chrome
/usr/bin/google-chrome
so now we are ready start it in single X Windows system by execute below command:
#/usr/bin/startx /usr/bin/google-chrome https://chanvicheka-ouk.com -- vt1
You might wonder what is -- vt1 for?
vt1 means we will display it in x windows system at virtual terminal number 1.
Linux in CLI has six virtual terminals total which you can switch between them using ctrl+alt+F# where # is the number of the terminal (1-6)
You can check your Oracle Linux Release by execute below command at the terminal
# sudo cat /etc/oracle-release
Ok, now it is the time to install Chrome
#sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
#sudo yum -y install redhat-lsb libXScrnSaver
#sudo yum -y localinstall google-chrome-stable_current_x86_64.rpm
Remark: If you run into following issue:
Error: Package: google-chrome-stable-88.0.4324.182-1.x86_64 (/google-chrome-stable_current_x86_64)
Requires: libvulkan.so.1()(64bit)
you can resolve it by execute following two commands:
#sudo yum-config-manager --enable ol7_optional_latest
#sudo yum -y localinstall google-chrome-stable_current_x86_64.rpm
Installed:
google-chrome-stable.x86_64 0:88.0.4324.182-1
Dependency Installed:
liberation-fonts.noarch 1:1.07.2-16.el7
liberation-mono-fonts.noarch 1:1.07.2-16.el7
liberation-narrow-fonts.noarch 1:1.07.2-16.el7
liberation-serif-fonts.noarch 1:1.07.2-16.el7
vulkan.x86_64 0:1.1.97.0-1.el7
vulkan-filesystem.noarch 0:1.1.97.0-1.el7