I'm using vim for programming along with a plugin that allows me to open a command console in the editor, which helps me execute my script, and as you know you need to save before executing, the problem I have with this is that I get it makes it very slow to have to escape and type :w every time I want to save a file to later execute it, so I need a keyboard shortcut that allows me to just save the file, just like in other editors you press ctrl + s to just save the file File, Archive.
I know a shortcut in vim that allows me to save and close a file: shift + zz , but the problem is that the editor closes me, how do I save only the file using a keyboard shortcut?
AgileSoul's questions
In all the programming languages that I have used, whenever you work with decimal numbers, they are represented with a point, which is contrary to several definitions such as:
Decimal numbers are those that are represented by a comma and that have an integer part (to the left of the comma) and another decimal part (to the right of the comma).
Concept taken from https://www3.gobiernodecanarias.org/medusa/ecoblog/crodalf/numeros-decimales-concepto/
either
We can say that a decimal number is one that is made up of an integer part and a decimal part, separated by a comma, and represents quantities that are not integers.
Definition taken from https://www.mundoprimaria.com/recursos-matematicas/numeros-decimales
For example in the programming console in javascript we make a simple division:
179/4
--> 44.75
It returns a decimal separated by a point and not by a comma. Why is this happening?
Note: If this question is not for this site please let me know.
I want to align a text, for example let's say I want to have 12 spaces to the right before the text. I tried this but I get left aligned and not right aligned:
printf "%12s" "texto" #-->
# texto
How can I get something like this?:
# texto
I get something like:
# Quiero que se ejecute un daemon hasta que se pulse control + c
trap 'handle_exit 0' SIGINT
# El ciclo solo es para esperar que pulsen ctrl + c
while true
do
sleep 1000000
done
Now, I want to know if there is a cleaner way to do that loop.
I'm trying to understand this code 100% but I'm not completely clear, especially because of the printf %02X
:
MAC_ADDRESS="AF:BA:44:2A:8F:3C"
# Se que sacamos un dijito a la derecha de la posicion '13' con ${MAC_ADDRESS:13:1}
printf %02X $((0x${MAC_ADDRESS:13:1} + 1))
#output:
10
I know that addition of hexadecimal numbers is being allowed, but I don't know what allows it or the purpose of it %02X
as the first argument to the command printf
.
# Algo raro es que al querer sumar "1 + D" me da un resultado erroneo, pues el resultado real deberia ser "0E"
printf %02X $((0x1+D))
#output:
01
I found 2>
in several lines of code like this:
cat miTexto.txt 2> /dev/null
I know it >
redirects the output to a file that will literally throw it away, but... why 2>
?
I 've also seen things like &>
which I think runs a command in the background and redirects the output, but I'm not sure. Get me out of doubt please.
I read that the option -a [Archivo]
inside a condition is true if the file exists, but now I run into this and realize the option -a
has nothing to do with the explanation above:
var1=1
var2=2
[ "$var1" -a "$var2" ] && echo true || echo false
The output is true
and I don't have any file named "1" or "2"; Now when one of the two variables or both are empty then:
var1=1
var2=""
[ "$var1" -a "$var2" ] && echo true || echo false
The output is now false
.
I don't understand what the option is doing -a
. I am reading a code and it uses that type of validation, someone explain to me: What is the function of that option?
Since I didn't find anything else on the internet.
I'm trying to understand a function created by > airmon-ng but when I get to this conditional line:
if [ ! "${InterfacePhysical// /}" ]; then
InterfacePhysical="$(ls -l "$interface_physical_path" | sed 's/^.*\/\([a-zA-Z0-9_-]*\)$/\1/')"
fi
Taking into account that InterfacePhysical="phy0"
What I don't understand is:
Why is the variable enclosed in braces? And what is the functionality of those "// /" that are between the braces?
If someone can make me understand what validates this condition, it would be very helpful.
I have an array of strings where the elements have different colors and I want to filter the strings that have the brown color.
#!/bin/bash
cafeRegex='^\e[0;33m*{*}\e[0m$'
arrayColores=($(echo -e "\e[0;33m3tia01\e[0m \e[0;37mabuela32\e[0m 2Yo3 \e[1;37mabuelo21\e[0m
\e[0;32m49hijo1\e[0m \e[0;36m8papa\e[0m \e[0;33m33mama11\e[0m"))
echo "El array: ${arrayColores[*]}"
for familiar in ${arrayColores[*]}
do
if [[ $familiar =~ $cafeRegex ]]; then
echo "Los familiares cafes son: $familiar"
fi
done
The output I have is this:
It shows me the array with its colors but the sentence to filter the brown color is not executed, I suspect the regular expression.
I create an array of ranges and print their number of elements:
arrayRanks=({A..D} {1..4})
echo "El array tiene ${#arrayRanks[*]} elementos"
I can add an element to the end of the array while updating its number of elements:
arrayRanks[${#arrayRanks[*]}]=33
echo "El array ahora tiene ${#arrayRanks[*]} elementos"
So far so good, but if I want to add a range or a set of elements through a range at the end of the array or at the beginning, how can I do it?
These two codes work:
if [ $animal = "perro" ]; then
echo "El animal es un perro"
else
echo "Se desconoce el animal"
fi
Y:
if [ $animal == "perro" ]; then
...
In one I used =
and in the other ==
to do a comparison in a Bash script.
Which one should you use? The normal equal ' = ' or the double equal ' == ' ?
I leave my script to help me understand where the error is and to be able to correct it:
#!/bin/bash
fechaDeNacimientoRegex='^19|20[0-9]{2}[1-12]{2}[1-31]$'
#Validacion y entrada de la fecha
read -p "Por favor ingresa la fecha formato [yyyyMMdd]:
" fechaNacimiento
if [[ $fechaNacimiento =~ $fechaDeNacimientoRegex ]]; then
echo "La fecha $fechaNacimiento es valida"
else
echo "La fecha $fechaNacimiento es invalida"
fi
The output when I enter a date between 1900 and 1999 works:
Por favor ingresa la fecha formato [yyyyMMdd]:
19921129
La fecha 19921129 es valida
But it doesn't work when I put 2000 or greater:
Por favor ingresa la fecha formato [yyyyMMdd]:
20110330
La fecha 20110330 es invalida