Bash 脚本通过 .desktop 保存到带有完整路径的可变外部文件名

Bash 脚本通过 .desktop 保存到带有完整路径的可变外部文件名

好吧,我尽量恢复我想做的事情。抱歉重复了,我不知道如何让这个问题更客观

我正在制作一个用于启动“mupen64plus”的第一个脚本,用于与“Xfce Desktop”和文件“”一起使用

mupen64plus.desktop当前内容

[Desktop Entry]
Version=1.0
Type=Application
Name=Mupen64Plus
GenericName=N64 Emulator
Comment=Nintendo 64 emulator and plugins for Linux, Mac OSX, FreeBSD, and Windows
Exec=xfce4-terminal --hold --execute /usr/bin/bash -c "/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus.geb" %F
Icon=/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/.mupen64plus.svg
MimeType=application/x-n64-rom;
Categories=Game;Emulator;
Keywords=Emulator;Nintendo64;Mupen64plus;
;NoDisplay=true

bash脚本的想法是以下几点

  1. 获取路径(脚本和绝对目录路径)

  2. 例如,获取具有绝对路径的外部文件并将其保存在名为ARCHIVO-/media/Inukaze1/N64/mupen64plus.v64或的变量中/media/Nicolas/Temporal/N64/ROMS/mupen64plus.v64

    因为 mupen64plus 需要文件的绝对路径来加载它。由于这个原因,因为路径可能完全不同,我需要将绝对路径存储在变量上(我更喜欢ARCHIVO在这种情况下调用变量)

    然后,只要是一个文件的值ARCHIVO,如果我选择多个文件(我不想意外打开具有不同 ROM 的多个 mupen64plus 实例),则并不重要

     ARCHIVO='/media/samba/Inukaze/ROMS/Nintendo 64/Demos/Nintro 64'
     # or
     ARCHIVO='/mnt/cifs/Temp/N64Homebrews/Bike Race ’98'
    

    使用的原因''是对于像这样的名称Bike Race ’98,如果我使用特殊字符可能会出现问题""

  3. 我已经写了一些脚本,但是很多,因为我曾经写过一些特定标题所需的东西。

  4. 通过.desktop文件启动mupen64plus,使用“打开方式”加载“N64 ROM”并正确启动ROM。

    您可以在网站上找到一些自制程序和演示,例如 nesworld 和/或 n64squid

好吧,我可以将我的脚本内容放在帖子上,因为会出现消息“正文限制为 30000 个字符;您输入了 41290”。

我当前的 mupen64plus.geb 脚本内容(我的母语是西班牙语,因为你可以看到很多西班牙语单词)

查看此 url 上的脚本 ->https://controlc.com/f3d25176

答案1

我写了太新的文件,只是为了尝试了解当我通过桌面文件运行脚本时发生了什么

第一个新建/home/inukaze/.local/share/applications/mupen64plus_test.desktop,内容为

[Desktop Entry]
Version=1.0
Type=Application
Name=Mupen64Plus TEST
GenericName=N64 Emulator
Comment=Nintendo 64 emulator and plugins for Linux, Mac OSX, FreeBSD, and Windows
Exec=xfce4-terminal --hold --execute /usr/bin/bash -c "/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus_test.geb" %k
Icon=/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/.mupen64plus.svg
MimeType=application/x-n64-rom;
Categories=Game;Emulator;
Keywords=Emulator;Nintendo64;Mupen64plus;
;NoDisplay=true

第二个是“/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus_test.geb”,内容是:

#!/usr/bin/env bash

#Determine in which directory i am located :
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
cd "$SCRIPTPATH"

#Get File Extension :
EXTENSION=$(echo "$1" | awk -F '.' '{print $NF}')

ARCH=$(uname -m)
case "$ARCH" in
    x86)    ARCH="x32"                      ;;
    i?86)   ARCH="x32"                      ;;
    amd64)  ARCH="x64"                      ;;
    x86_64) ARCH="x64"                      ;;
    * ) echo    "Your Architecture '$ARCH' -> Is not supported."    ;;
esac

ROMFILE="%k"    #I suppose i need redirect .desktop file %k to this bash variable called $ROMFILE
                            #To storage the absolute path of rom file. but is just an idea
                            
if [ "$ARCH" == "x64" ]
then
        export LD_LIBRARY_PATH="./.libs/64Bits":$LD_LIBRARY_PATH
        EJECUTABLE=".mupen64plus.x64"
fi

if [ "$ARCH" == "x32" ]
then
        export LD_LIBRARY_PATH="./.libs/32Bits":$LD_LIBRARY_PATH
        EJECUTABLE=".mupen64plus.x32"
fi

if [ -z "$1" ]
then
        echo ""
        echo -e "First Argument is Empty Variable\n"
        echo ""
else
        echo ""
        echo -e "First Argument is a File ; Check md5sum"
        MD5=$(md5sum "$1"| tr a-z A-Z | awk '{print $1}')
        echo ""
        echo 'Inside "if [ -z "$1"] else '
        echo "Reveal variable content : "
        echo '"$@"' = "'"$@"'"
        echo '"$*"' = "'"$*"'"
        echo '"$1"' = "'"$1"'"
        echo '"$2"' = "'"$2"'"
        echo '"%k"' = %k
        echo ""
        echo "Now First Try to run mupen64plus : without another script"
        ./.mupen64plus.x64 --corelib "./.libs/64Bits/libmupen64plus.so.2.0.0" --datadir "." --configdir "." "$@"
        echo "This work"
        echo "Now Second Try to run mupen64plus : via another script"
        bash -c "'"/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus.geb"'" < "$1"
        echo "This not work"
fi

echo -e ""
echo "i need when mupen64plus script run for any folder store the absolute path of rom i want to run"
echo "For example : "
echo -e ""
echo '"/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus.geb"' "'"/media/Nicolas/Temporal/ROMS/N64/Mupen64Plus.v64"'"
echo -e ""
echo "The first is absolute path my script"
echo "and the second is the absolute path of romfile"
echo "on another very diferent directory"
echo -e ""
echo "i don't have idea how redirect absolute path of romfile from .desktop file"
echo "to bash variable before the mupen64plus execute"

exit 0

我注意到我通过父脚本或桌面文件运行了一个“子”脚本,父或桌面文件中的变量不会传输到子脚本,我认为这是我应该解决的问题,以使其工作,我需要它。

如果我在终端上使用以下命令

cd /tmp
"/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus_test.geb" '/media/Nicolas/Temporal/ROMS/N64/Mupen64Plus.v64'

输出是:

来自父脚本:

First Argument is a File ; Check md5sum

Inside "if [ -z "$1"] else 
Reveal variable content : 
"$@" = '/media/Nicolas/Temporal/ROMS/N64/Mupen64Plus.v64'
"$*" = '/media/Nicolas/Temporal/ROMS/N64/Mupen64Plus.v64'
"$1" = '/media/Nicolas/Temporal/ROMS/N64/Mupen64Plus.v64'
"$2" = ''
"%k" = %k

Now First Try to run mupen64plus : without another script
 __  __                         __   _  _   ____  _             
|  \/  |_   _ _ __   ___ _ __  / /_ | || | |  _ \| |_   _ ___ 
| |\/| | | | | '_ \ / _ \ '_ \| '_ \| || |_| |_) | | | | / __|  
| |  | | |_| | |_) |  __/ | | | (_) |__   _|  __/| | |_| \__ \  
|_|  |_|\__,_| .__/ \___|_| |_|\___/   |_| |_|   |_|\__,_|___/  
             |_|         https://mupen64plus.org/               
Mupen64Plus Console User-Interface Version 2.5.9

UI-Console: attached to core library 'Mupen64Plus Core' version 2.5.9
UI-Console:             Includes support for Dynamic Recompiler.
Core: Using full mem base
Core: Goodname: Mupen64Plus Demo by Marshallh (GPL)
Core: Name: Mupen64Plus         
Core: MD5: DBF04773EC2B8ADF8A94DB7E3E461138
Core: CRC: DDBA4DE5 B107004A
Core: Imagetype: .v64 (byteswapped)
Core: Rom size: 1048576 bytes (or 1 Mb or 8 Megabits)
Core: Version: 1444
Core: Manufacturer: 0
Core: Country: Demo
UI-Console Status: Cheat codes disabled.
UI-Console: using Video plugin: 'Glide64mk2 Video Plugin' v2.5.9
UI-Console: using Audio plugin: 'Mupen64Plus SDL Audio Plugin' v2.5.9
Input: Using auto-config file at: './InputAutoCfg.ini'
Input: Using auto-config file at: './InputAutoCfg.ini'
UI-Console: using Input plugin: 'Mupen64Plus SDL Input Plugin' v2.5.9
UI-Console: using RSP plugin: 'Hacktarux/Azimer High-Level Emulation RSP Plugin' v2.5.9
Video: opening ./Glide64mk2.ini

Video: 3DNOW! detected.

Core: input plugin did not specify a render callback; there will be no on screen display by the input plugin.
Input: 2 SDL joysticks were found.
Input: N64 Controller #1: Using manual config with no SDL joystick (keyboard/mouse only)
Input: Using auto-config file at: './InputAutoCfg.ini'
Input: N64 Controller #2: Using auto-config with SDL joystick 0 ('Twin USB Joystick')
Input: Using auto-config file at: './InputAutoCfg.ini'
Input: N64 Controller #3: Using auto-config with SDL joystick 1 ('Twin USB Joystick')
Input: 3 controller(s) found, 3 plugged in and usable in the emulator
Input Warning: Couldn't open rumble support for joystick #1
Input: Rumble activated on N64 joystick #2
Input: Rumble activated on N64 joystick #3
Input Warning: Couldn't open rumble support for joystick #4
Input: Mupen64Plus SDL Input Plugin version 2.5.9 initialized.
RSP Error: Can't load library: mupen64plus-rsp-z64.so
Core: Using video capture backend: dummy
Core: Game controller 0 (Standard controller) has a Memory pak plugged in
Core: Game controller 1 (Standard controller) has a Memory pak plugged in
Core: Game controller 2 (Standard controller) has a Memory pak plugged in
Core: Game controller 3 (Standard controller) has a Memory pak plugged in
Core: Using CIC type X102
Video: Using TEXUMA extension.

&ConfigOpenSection is 0x7fcfd3f7e688
(II) Setting video mode 1058x885...
Core: Setting video mode: 1058x885
Congratulations, you have 4 auxilliary buffers, we'll use them wisely !
packed pixels extension used
NPOT extension used
use_fbo 1
Video: InitCombine() 
Video: extensions 
Video: initialized.
Video: 

Audio: Using resampler speex
Audio: Initializing SDL audio subsystem...
ALSA lib pcm_direct.c:1568:(_snd_pcm_direct_get_slave_ipc_offset) Invalid value for card
Input Warning: Couldn't open rumble support for joystick #1
Input: Rumble activated on N64 joystick #2
Input: Rumble activated on N64 joystick #3
Input Warning: Couldn't open rumble support for joystick #4
Core: Initializing 4 RDRAM modules for a total of 8 MB
Core: Starting R4300 emulator: Dynamic Recompiler
Core Status: Stopping emulation.
Core: R4300 emulator finished.
Core Status: Rom closed.
This work

Now Second Try to run mupen64plus : via another script

来自脚本子

Autor ----------------> Inukaze ( Venezuela )
Sitio ----------------> https://goo.gl/ij6WqW
Correo-E -------------> [email protected]
Licencia -------------> GPL 2

******* Inicio : Acerca de este Guión ********

  Yo intento escribir guiones compatibles con
   Sistemas operativos Unix & POSIX , y otros
   Sistemas operativos que soporten bash

  Este archivo es un guion sencillo para
  Iniciar "mupen64plus"
  [Emulador de Nintendo 64]

******** Fin : Acerca de este Guión **********


Antes del -z "$@" de 64 Bits
"$@" = ''
"$*" = ''
"$1" = ''
"$2" = ''
"%k" = '%k'
Despues del -z "$@" de 64 Bits
"$@" = ''
"$*" = ''
"$1" = ''
"$2" = ''
"%k" = '%k'
 __  __                         __   _  _   ____  _             
|  \/  |_   _ _ __   ___ _ __  / /_ | || | |  _ \| |_   _ ___ 
| |\/| | | | | '_ \ / _ \ '_ \| '_ \| || |_| |_) | | | | / __|  
| |  | | |_| | |_) |  __/ | | | (_) |__   _|  __/| | |_| \__ \  
|_|  |_|\__,_| .__/ \___|_| |_|\___/   |_| |_|   |_|\__,_|___/  
             |_|         https://mupen64plus.org/               
Mupen64Plus Console User-Interface Version 2.5.9

UI-Console: attached to core library 'Mupen64Plus Core' version 2.5.9
UI-Console:             Includes support for Dynamic Recompiler.
Core: Using full mem base
UI-Console Error: no ROM filepath given

来自父脚本

This not work

i need when mupen64plus script run for any folder store the absolute path of rom i want to run
For example : 

"/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus.geb" '/media/Nicolas/Temporal/ROMS/N64/Mupen64Plus.v64'

The first is absolute path my script
and the second is the absolute path of romfile
on another very diferent directory

i don't have idea how redirect absolute path of romfile from .desktop file
to bash variable before the mupen64plus execute

我需要子脚本使用父脚本中的 romfile 绝对路径来正确启动 mupen64plus 和 rom 文件

好吧,如果我使用“Thunar”中的“Open with”运行,输出如下

First Argument is Empty Variable



i need when mupen64plus script run for any folder store the absolute path of rom i want to run
For example : 

"/media/Compartido/Lignux/Videojuegos/Emulador/Nintendo/64/mupen64plus/portable/mupen64plus.geb" '/media/Nicolas/Temporal/ROMS/N64/Mupen64Plus.v64'

The first is absolute path my script
and the second is the absolute path of romfile
on another very diferent directory

i don't have idea how redirect absolute path of romfile from .desktop file
to bash variable before the mupen64plus execute

相关内容