No matter what OS, no matter if it has a GUI, no matter if it uses systemd or sysvinit, are there any executable files that are going to exist in 100% of linux releases?
Weird question, I know. The reason why I ask is because I need a foolproof way of detecting whether what CPU architecture a given OS is meant for 32-bit, 64-bit, armhf, x86, you name it. And the detection must be done automatically and silently using a bash script.
(I thought the easiest way to detect it would be to find an executable file and detect what CPU architecture it's meant for)
Is there any executable file that is 100% going to be in /bin?
Want to run Minecraft Java on your RPi? Easiest way is with Pi-Apps - just click Install.
https://github.com/Botspot/pi-apps
Pi-Apps also includes Zoom, Visual Studio, Tor browser, Windows 10 theme, and 33 more.
Over 50,000 users!
https://github.com/Botspot/pi-apps
Pi-Apps also includes Zoom, Visual Studio, Tor browser, Windows 10 theme, and 33 more.
Over 50,000 users!
Re: Is there any executable file that is 100% going to be in /bin?
Do you mean like "file /bin/sh" ?Botspot wrote: ↑Mon Oct 12, 2020 9:41 pmNo matter what OS, no matter if it has a GUI, no matter if it uses systemd or sysvinit, are there any executable files that are going to exist in 100% of linux releases?
Weird question, I know. The reason why I ask is because I need a foolproof way of detecting whether what CPU architecture a given OS is meant for 32-bit, 64-bit, armhf, x86, you name it. And the detection must be done automatically and silently using a bash script.
(I thought the easiest way to detect it would be to find an executable file and detect what CPU architecture it's meant for)
I think /bin/sh will always be there even if its a link to /bin/dash
Pi4 8GB and Pi4 4GB running Raspberry Pi OS 64-bit
Re: Is there any executable file that is 100% going to be in /bin?
That could probably work.
But I'd have to find a way to follow the symlink or else when I try to detect the mimetype it will look like this:
Code: Select all
$ file --mime-type -b /media/pi/pi-power-tools/bin/sh
inode/symlink
Want to run Minecraft Java on your RPi? Easiest way is with Pi-Apps - just click Install.
https://github.com/Botspot/pi-apps
Pi-Apps also includes Zoom, Visual Studio, Tor browser, Windows 10 theme, and 33 more.
Over 50,000 users!
https://github.com/Botspot/pi-apps
Pi-Apps also includes Zoom, Visual Studio, Tor browser, Windows 10 theme, and 33 more.
Over 50,000 users!
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Is there any executable file that is 100% going to be in /bin?
You'll always have /sbin/init as that's the program that the kernel starts (unless you override it in /boot/cmdline.txt).
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Re: Is there any executable file that is 100% going to be in /bin?
Another good answer. Too bad init can also be a symlink. Though again, I suppose the script could handle that and follow the symlink before getting the filetype.DougieLawson wrote: ↑Mon Oct 12, 2020 9:50 pmYou'll always have /sbin/init as that's the program that the kernel starts (unless you override it in /boot/cmdline.txt).
Want to run Minecraft Java on your RPi? Easiest way is with Pi-Apps - just click Install.
https://github.com/Botspot/pi-apps
Pi-Apps also includes Zoom, Visual Studio, Tor browser, Windows 10 theme, and 33 more.
Over 50,000 users!
https://github.com/Botspot/pi-apps
Pi-Apps also includes Zoom, Visual Studio, Tor browser, Windows 10 theme, and 33 more.
Over 50,000 users!
Re: Is there any executable file that is 100% going to be in /bin?
why not just do /bin/bash
i figure if it's a bash script & there's no bash your screwed anyways. i've never come across a linux without a bash shell or i don't remember.
i figure if it's a bash script & there's no bash your screwed anyways. i've never come across a linux without a bash shell or i don't remember.

Last edited by kerry_s on Mon Oct 12, 2020 10:34 pm, edited 1 time in total.
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Is there any executable file that is 100% going to be in /bin?
If you're doing it in busybox then /bin/busybox must exist (unless you have some funky way of launching busybox).
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Re: Is there any executable file that is 100% going to be in /bin?
POSIX mandates that /bin/sh must exist.
Pi4 8GB and Pi4 4GB running Raspberry Pi OS 64-bit
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Is there any executable file that is 100% going to be in /bin?
On RaspiOS that's a symlink to /bin/dash.
Code: Select all
pi@ulysses:/bin $ ls -la sh
lrwxrwxrwx 1 root root 4 Jun 20 2019 sh -> dash
pi@ulysses:/bin $ readlink /bin/sh
dash
pi@ulysses:/bin $
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
-
- Posts: 1278
- Joined: Tue Mar 20, 2018 9:53 pm
Re: Is there any executable file that is 100% going to be in /bin?
Busybox based distributions don't have bash. Also if busybox is used as the init for a distribution then init is a script.
Re: Is there any executable file that is 100% going to be in /bin?
What are you trying to achieve by doing this anyway? The requirement it must work on everything is going to give you lots of weird edge cases to deal with like a multi arch install of Debian. Are you trying to write a system information script?
-
- Posts: 1278
- Joined: Tue Mar 20, 2018 9:53 pm
Re: Is there any executable file that is 100% going to be in /bin?
I agree there is going to be somewhere that doesn't put things in the same place or you have a 64 bit kernel and a 32 bit user land.
I was going to suggest parsing the uname output but then you might have trouble with that one too.
I was going to suggest parsing the uname output but then you might have trouble with that one too.
-
- Posts: 2509
- Joined: Sat Aug 18, 2012 2:33 pm
Re: Is there any executable file that is 100% going to be in /bin?
DougieLawson wrote: ↑Mon Oct 12, 2020 9:50 pmYou'll always have /sbin/init as that's the program that the kernel starts (unless you override it in /boot/cmdline.txt).
Code: Select all
[root@amd-nixos:~]# ls -l /sbin
ls: cannot access '/sbin': No such file or directory
[root@amd-nixos:~]# ls -l /lib
ls: cannot access '/lib': No such file or directory
[root@amd-nixos:~]#
Re: Is there any executable file that is 100% going to be in /bin?
If you are going to use file to detect the mimetype, doesn't that imply that the file program is installed and working? If it is, then use file to check whether file itself is a 32-bit or 64-bit executable.Botspot wrote: ↑Mon Oct 12, 2020 9:47 pmThat could probably work.
But I'd have to find a way to follow the symlink or else when I try to detect the mimetype it will look like this:Code: Select all
$ file --mime-type -b /media/pi/pi-power-tools/bin/sh inode/symlink
Code: Select all
$ file /usr/bin/file
/usr/bin/file: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=7df606942d83740a79979415e18b9960f0344ff2, stripped
Re: Is there any executable file that is 100% going to be in /bin?
I usually start with 'uname' and work from there but to answer your question, I guess we need to find a native executable using minimum tools..
The above ought to work for other unix as well, BSD's etc that don't have things like /proc/version and /etc/(os-release|redhat-release) and so forth. For instance, the above 'readlink' could be simplified via "-m" option but the BSD's don't have it.
Code: Select all
#!/usr/bin/env sh
E="/bin/sh"
[ -f "$E" ] || exit 1
X=$(readlink "$E")
[ -z "$X" ] && X="$E"
X="$(which $X)"
$(which file) "$X" || exit 1