Home > database >  Copying all .desktop files to ~/.local/share/applications/
Copying all .desktop files to ~/.local/share/applications/

Time:03-21

I'm trying to write a bash script to copy all .desktop files under /nix/store to ~/.local/share/applications/. I'm not particular good with bash, so I would like assistance. I used the find command to find all files. Now I'm trying to create an array from the output with the help of readarray:

files=$(find /nix/store -type f -name \*.desktop)
echo $files
x=$(readarray -d 's'  <<<$files)
echo $x

The echo $files will print the result of the find command, however the echo $x prints an empty line.

CodePudding user response:

#!/usr/bin/env bash

files=$(find /nix/store -type f -name \*.desktop)

readarray array <<<$files

for i in ${array[@]}; do
    cp $i ~/.loca/share/applications/
done

or

find /nix/store -type f -name \*.desktop -exec cp {} ~/.local/share/applications/ \;

CodePudding user response:

Copying all .desktop files to ~/.local/share/applications/

find /nix/store -type f -name '*.desktop' \
   -exec cp -v {} ~/.local/share/applications/ ';'

however the echo $x prints an empty line.

readarray produces no output. Instead, it stores the lines in the argument, which represents the name of the variable, the name of the array.

readarray -d 's'  <<<$files
#            ^^^  - stores output in array named s
printf "%s\n" "${s[@]}"  # you can print the array s

CodePudding user response:

If I'm not wrong and /nix/store/ is a regular directory, this should work:

cp /nix/store/*.desktop ~/.local/share/applications/
  • Related