Segundo plano en Bash – Stack Overflow en español

¿Exactamente cómo quieres que funcionen? Si desea que se inicien en segundo plano y se ejecuten secuencialmente , haría algo como esto:

{ sleep 2; sleep 3; } &

Si desea sleep 3ejecutar solo si sleep 2tiene éxito, entonces:

sleep 2 && sleep 3 &

Si, por otro lado, desea que se ejecuten en paralelo en segundo plano, puede hacer esto:

sleep 2 & sleep 3 &

Y las dos técnicas podrían combinarse, tales como:

{ sleep 2; echo first finished; } & { sleep 3; echo second finished; } &

Siendo bash, a menudo hay una multitud de técnicas diferentes para realizar la misma tarea, aunque a veces con diferencias sutiles entre ellas.

bash function to “wrap” 7z

It appears that 7z can’t write to a pipe, so I wrote the following bash function to emulate this functionality.

I know this is a simple problem, but this is my first bash function and I feel like it’s really easy to write faulty code in bash, so any feedback is appreciated.

function 7z2pipe () (
    local out_dir=$(mktemp -d)
    local out_file="${out_dir}"/temp.7z
    local log_file="${out_dir}"/"outz.txt"

    7z -p"weak_password" -mhe=on a "${out_file}" "$@" &> "${log_file}"
   
    if ( $? -ne 0  ); then
        cat "${log_file}"
        return $?
    fi

    cat "${out_file}"
)

bash – Linux program installation issue regarding utility dependencies and PATH

I am trying to run a program that requires the MUMmer program to be installed, and MUMmer requires its own dependencies. During my initial attempt at installation of MUMmer following their installation guide I ran “make check” and found that multiple needed utilities were not found (I included an image below). I know that at least several of these utilities are installed and are commands I can use, however I cannot figure out why this installation is unable to access them. I tried adding their location to PATH but that did not help. Any time “PATH” is involved I seem to have issues with whatever I’m trying to do. The whole PATH structure and how I am consistently running into issues with it is confusing to me. Please help!

Installation error

bash – ds4mac – directory switcher for macOS/Linux: the installer script

In this post, I present the bash script for installing the ds4mac:

#!/usr/bin/env bash

script_magic="alias ds='source ~/.ds/ds_script'"

echo "Installing ds..."

grep "$script_magic" ~/.bashrc 

if ( $? != 0 ); then
    echo "$script_magic" >> ~/.bashrc   
    echo "~/.bashrc updated!"
else
    echo "~/.bashrc is already updated."
fi

# Create files:
echo "Creating files..."
mkdir -p ~/.ds
echo "Created the .ds directory."
make > /dev/null
cp ds_engine ~/.ds/ds_engine
echo "Built the ds_engine."
tag_file=~/.ds/tags
touch $tag_file

add_tag_to_file () {
    grep $1 $tag_file > /dev/null
    if ( $? != 0 ); then
        echo $1 $2 >> $tag_file
        echo Setting the tag $1 to directory $2 done.
    fi
}

# Populate the default 
echo "Populating the tag file with default tags..."

add_tag_to_file "docs" "~/Documents"
add_tag_to_file "down" "~/Downloads"
add_tag_to_file "root" "/"
add_tag_to_file "home" "~"
add_tag_to_file "ds"   "~/.ds"

echo "Done populating the tag file with default tags."
echo "Copying the script..."

cp ds_script ~/.ds/ds_script

echo "Done! ds will be available for use in your next shell session. :-)"

(The entire project is here.)

See also

  1. The main script
  2. The tag engine

Critique request

Please, tell me anything that comes to mind. ^^

bash – How to recursively convert all JPGs into one PDF in each folder using img2pdf?

I have three levels of folders like main, sub-1 and sub-2. my main folder has lot of sub-1 folders and sub-1 has lot of sub-2 folder with JPG images inside.

I copy JPG files from sub-2 to its parent sub-1 folder FROM main folder by using this command.

find . -type f -name "*.jpg" -exec sh -c 'for p; do
  cp "$p" "${p%/*/*}"
done' _ {} +

Now I have to convert all jpgs into one pdf file inside each sub-1 folder from my MAIN folder, so there will be my all copied jpgs along with converted pdf in sub-1 (pdf name should be the folder name ex: sub-1). after convert finished I have to delete the copied jpgs only inside sub-1 folder (not original jpgs), so there will be many sub-2 folders with a single pdf file.

I am using img2pdf library to covert my images. and I tried this command below it does not do the work, I could not find any solution. Now how do I make this works?

find . -name '*.jpg' -type f -exec bash -c 'img2pdf *.jpg -o "${PWD##*/}".pdf' {} + 

Is there an easy Windows equivalent to this search in Bash?

If I type

locate something | grep "someEnding$"

in a shell it will take a second to give me a list of every file on my system where the absolute path contains ‘something’ and ends ‘someEnding’.

If there a way to do this in Windows? Preferably quickly, but OK if not.

bash – tar -xvf error “Can’t restore time” when trying to extract in certain directories on mac osx but works in others

Strangest thing.

I downloaded the openjdk release here: https://jdk.java.net/16/

When running tar -xvf on the file in the ~/Downloads directory it works fine.

But when running in /tmp or another directory I have in my home folder I get the error: “Can’t restore time”

Anybody seen this before?

bash – How do I save the values from the zenity form to a variable

How do I save the values from the zenity forms to a variable (or file.txt), to use with “echo $value”

This is my command:

zenity --forms --title="mysql" --text="Enter MySQL Data" --separator="," --add-entry="USER" --add-entry="PASSWORD" --add-entry="DBNAME" --ok-label "Yes" --cancel-label "Cancel"

enter image description here

How to turn ON/OFF "Force GPU rendering" using bash command

Please how can I toggle "Force GPU rendering" ON/OFF programmatically from shell?

Things I have tried:

  1. setprop debug.hwui.force_gpu_rendering true
  2. setprop debug.hwui.gpu 1

All the above didn’t turn it ON/OFF please help!

Limpar histórico do bash no Kali Linux

As pesquisas que eu fiz sobre limpar o histórico do bash foram inúteis. Eu usei history -c, mas o terminal não aceitou uma opção -c, nem -w. Eu tentei apagar o arquivo /.bash_history, mas não existe o arquivo /home/usuario/.bash_history. O Bleachbit também não trabalhou nesse sentido.