Bash script : Unexpected error when running a command

My script is started from a .desktop file on usb stick.

#!/usr/bin/env xdg-open
[Desktop Entry]
Comment[en_US]=main preliminary script machine
Comment=main preliminary script machine
Exec=/run/media/$(logname)/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/001_01_FIRST_REBOOT_FIRST_SCRIPTS/main_first_reboot_machine_script.sh
GenericName[en_US]=main preliminary script machine
GenericName=main preliminary script machine
Icon=system-run
MimeType=
Name[en_US]=main preliminary script machine
Name=main preliminary script machine
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s–noclose
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

this piece of code return the expected value :

echo
echo 3
echo
echo “ls -al /run/media/$(logname)/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh”
ls -al /run/media/$(logname)/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh

echo

return :

ls -al /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh
-rwxrwxr-- 1 user_install user_devp 36337 18 févr. 22:50 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh

Next command return an unexpected error :

echo
echo 4
echo
echo .
echo “source : /run/media/$(logname)/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh”
echo
source : /run/media/$(logname)/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh

the error is ; No such file or directory

4

.
source : /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh

/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/001_01_FIRST_REBOOT_FIRST_SCRIPTS/main_first_reboot_machine_script.sh: line 177: :: No such file or directory

Any comment is welcome.

You seriously expect everyone immediately know what is on line 177 of your script?

It is just the copy of the error.
The number line has no interest.
What is important is the command :

source : /run/media/$(logname)/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/001_SCRIPTS/000_MY_FUNCTIONS/my_functions.sh

Is it possible that the use of ‘$(logname)’ is not allowed in this situation?

In a terminal, I would like to know why

ls /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/002_DATA/SYSTEM_CONFIG/2023_10_21/etc/zzzz1_system_common_function_full.sh

Return good value

/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/002_DATA/SYSTEM_CONFIG/2023_10_21/etc/zzzz1_system_common_function_full.sh

and why

source : /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2024_02_01_19h00/MY_PROJECTS/MY_INSTALL_STEP_1/2024_02_01_19h00/002_DATA/SYSTEM_CONFIG/2023_10_21/etc/zzzz1_system_common_function_full.sh

return error

bash: :: No such file or directory

PS : All script files are owned by user_install:user_devp
All script files have mode 774
Current script files is run by user_install
User user_install belongs to group users and group user_devp

What happens if you execute the ls command right before the attempted execution, as well as putting in echo $(logname)?

I will test this week-end a small program to check if the problem comes from where the program is called/run or if it is due to the running user.

I will give news on monday.

Thank you for helping.

I have not had the time to move forward on my problem. I give news as soon as I can.

I just figured it out, I believe. The issue is the colon after “source”. The double colon is the formatting for when the error is displayed - if you had said “source unknown.sh”, the error would have been “bash: unknown.sh: No such file or directory”. But because you’ve put a colon there, it’s parsing that as a filename and that’s why you see “bash: :: No such file or directory”. (The bolded colon is the filename in the error message)

Get rid of that colon and you should be fine.

Brilliant, hadn’t seen that one.

I only noticed it because I was reading it over and questioned how source was used in bash (I’ve only used . includefile.sh in my scripts typically), but the syntax looked off to me when I came back to look at it again in the middle of the night a couple days ago.

1 Like

Did you sleep sometimes ? :+1:
Thank you very much indeed.
Sorry about all the fuss.

1 Like

I did get some sleep - thanks for asking! And glad to help out - and that this solved the issue for you. :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.