date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,453,750,202,000
I'm using Linux arch 3.15.2-1-ARCH x86_64. I don't use zsh (zsh-5.0.5-1) every day, otherwise I would have noticed it segfaults, when I launch it from the bash cli: arch kernel: zsh[2187]: segfault at 8 ip 00007f3b49853083 sp 00007fff2ad39198 error 4 in libc-2.19.so[7f3b497d2000+1a4000] arch systemd-coredump[2188]: Pr...
The behavior can be reproduced with: export HISTSIZE=V= For some reason I had that in my .bashrc file. Most likely I didn't have focus in the window I thought I had, ended up adding V= without noticing it and was careless saving the file; maybe it was open in the editor - those are set to enable unlimited history. Bu...
Issue with zsh segfaulting: how to further assess the issue?
1,453,750,202,000
What are the steps that the Linux kernel does whenever the hardware raises segfault. Right now I know that through the IDT, the fault handler handles it, and somewhere along the road there is a message in the kern.log (dmesg) about the fault. I am asking this question because I am developing an hypervisor, and wheneve...
arch/x86/kernel/idt.c:152 - page_fault is used in the IDT arch/x86/entry/entry_64.S:1143 - page_fault is defined as a wrapper function for do_page_fault(), implemented using the macro idtentry arch/x86/entry/entry_64.S:847 - idtentry macro arch/x86/mm/fault.c:1562 - do_page_fault() Once you reach do_page_fault(), yo...
What happens whenever there is a segfault in linux
1,453,750,202,000
How to restart systemd after it crash? systemd currently crash during VirtualBox installation. Problem is already tracked by this issue#10716. I'm using Ubuntu 18.10. sudo dpkg -i virtualbox-5.2_5.2.20-125813_Ubuntu_bionic_amd64.deb Setting up virtualbox-5.2 (5.2.20-125813~Ubuntu~bionic) ... addgroup: The group `vboxu...
You cannot. Once systemd has reached this state, there is no way out. It is an infinite loop in the systemd program. You will have to wait for the actual bugs (one in Oracle's barmy VirtualBox post-installation procedures, q.v., and one in systemd when daemon-reexec is called often) to be fixed. Oracle's barmy post-i...
restart systemd after it crash
1,453,750,202,000
When I run GUFW as root, it returns: No protocol specified Unable to init server: Could not connect: Connection refused No protocol specified Unable to init server: Could not connect: Connection refused (gufw.py:5272): Gdk-CRITICAL **: gdk_keymap_get_for_display: assertion 'GDK_IS_DISPLAY (display)' failed (gufw.py:...
Type the following command in a terminal: echo $XDG_SESSION_TYPE If it returns Wayland, type: xhost si:localuser:root to allow root to start graphical apps under Wayland sessions.
GUFW returns a segmentation fault in line 13
1,453,750,202,000
I'm now reading The Shellcoder's Handbook: Discovering and Exploiting Security Holes, 2nd Edition. In the second chapter considered the simple buffer overflow problem like this (C code): int main () { int array[5]; int i; for (i = 0; i <= 255; i++ ) { array[i] = 10; } } Author compiled the cod...
First of all, you need to check the core file size in your limits using ulimit command (in bash or in zsh). # ulimit -c 0 If it's zero, you need to increase it. For instance, to increase it to unlimited: # ulimit -c unlimited # ulimit -c unlimited Secondly, you need to check where the coredump is created. ...
Core dump not written on segmentation fault
1,453,750,202,000
I have a Raspberry Pi server with Raspbian OS: Kernel: Linux 4.9.35+ #1014 Fri Jun 30 14:34:49 BST 2017 armv6l GNU/Linux Description: Raspbian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie Today I noticed that attempts to use mysql end in a segmentation fault. user@host~ $ mysql -u root -p Ente...
You most likely have corrupted binaries/and or a corrupted filesystem/SD card. The SD cards are not meant for heavy I/O use and degrade over time; Raspberry(es) are also known to corrupt data in SD cards when turning off occasionally due to characteristics of their design (electronics is not my area, not able to get ...
Mysql segfaulting when used from the shell
1,453,750,202,000
I am trying to check a mounted partition to see if the drive has errors: [root@virtuality ~]# /sbin/badblocks -v /dev/sdb1 Segmentation fault Uh oh. What does this mean? Why is badblocks segfaulting? Can I fix it? (System is CentOS release 4.6, drive is an SATA drive) EDIT: Using strace: [root@virtuality ~]# strace /...
Turned out this was a numbskull error, looks like my copy of badblocks may have just had a bug. I ran yum update and after that, badblocks no longer segfaults.
Why is badblocks segfaulting?
1,453,750,202,000
I tried asking my question on TI's forum, but I am not getting much feedback, so I thought I'd try my luck here. You can see my ongoing discussion with TI here: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1158936/am3359-caught-segv-when-distro-s-systemd-starting We have been working with ...
This issue was fixed on the TI Forum, here is the link for those interested. https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1158936/am3359-caught-segv-when-distro-s-systemd-starting In summary, the issue was that my VDD_MPU(1.1V) was driven by my PMIC and the PMIC driver was not properly ini...
AM335x - Custom Board <SEGV> when running Systemd
1,453,750,202,000
I can redirect stdout and stderr of a program using ./a.out > output.txt 2> error.txt But these don't redirect messages like segmentation faults. So I found { ./a.out < $TEST_DIR'test'$i'.in' > $OUTPUT_DIR/output$i.txt ; } 2> $OUTPUT_DIR/error$i.txt Yet, the core dump and stack smash messages are not getting redire...
The "Segmentation Fault" messages are not printed by the faulting program, but by the shell. The *** stack smashing detected *** & backtrace + memmap messages (at least on my system) are printed by the stack protector handler directly to the the controlling terminal (_PATH_TTY/dev/tty is opened directly, with no regar...
How to redirect Core dump and stack smash messages
1,453,750,202,000
I'm having a strange occurrence on my Raspbian Raspberry Pi, as most programs are now segfaulting before they even start: user@raspberrypi:~ $ sudo -s Segmentation fault user@raspberrypi:~ $ ssh -vvv localhost Segmentation fault user@raspberrypi:~ $ sudo reboot Segmentation fault user@raspberrypi:~ $ sudo apt update S...
I've had the same and a number of times (I don't remember how many, but at least two). I eventually came to consider this a fatal situation. The only thing that worked for me was a completely new installation. What I blame for this is the magnetic card. That's only my guess, I don't have any arguments. Well, I might h...
Most programs suddenly segfault
1,453,750,202,000
Using Arch Linux everytime I try to use Python interactive mode no matter what I type I get Segmentation fault (core dumped) and the Python interpreter exits. I do not have any problem running Python scripts or doing something like: $ echo "print(1+1)" | python But when I enter interactive mode, whether it is with py...
Following meuh suggestion I ran Python with strace and look at the differences between interactive and non-interactive Python. Interactive Python read my ~/.inputrc as it uses readline, and this was the file that was causing the Segmentation fault (core dumped). I had an ~/.inputrc which came from another machine (Ubu...
Python Interactive mode on Arch Linux "Segmentation fault (core dumped)"
1,453,750,202,000
On my build of Arch Linux I've recently noticed a weird problem. After launching certain programs from the shell it will echo "Segmentation Fault (core dumped)". Some examples of this are when I close shutter, launch chrome, launch sublime text, or close emacs. As far as I can tell the segfaults aren't affecting the p...
There are two common sources for this kind of problem (i.e. affecting multiple unrelated programs) Faulty memory. Use memtester or memtest86 to test your memory. Replace any bad DIMMs. If your motherboard supports it, buy ECC RAM - it's usually only 10-30% more expensive. Note that some distros (e.g. debian) are...
After some commands, bash prints "Segmentation Fault (core dumped)" for unknown reason
1,453,750,202,000
I'm currently trying to set up a MySQL replication and I don't have a /etc/sysconfig/iptables. So I tried to install it with yum install. It showed the following output. Installed Packages Name : iptables Arch : x86_64 Version : 1.4.7 Release : 11.el6 Size : 836 k Repo : installe...
Check what CPU architecture you have on your system. You're likely mixing the 32-bit and 64-bit binaries and libraries together which is probably giving you this error message. You can find out with this command: # 64-bit system $ getconf LONG_BIT 64 # 32-bit system $ getconf LONG_BIT 32 If you have 32 then you shou...
Segmentation fault (core dumped) when try to run iptables rhel6
1,453,750,202,000
I plan to run an Electron app on my UDOO Neo i.MX6 board with the official st1232 7'' touchscreen kit for UDOO Neo. I created a custom Linux distro with Poky (thud branch) to be able to build a "ready to boot" image. I enabled the "x11-base" image feature to have all the Xorg packages and I have the meta-freescale lay...
I simply added this patch to my layer and now it works.
How to configure X11 for embedded i.MX6 board with touchscreen?
1,453,750,202,000
Today I installed Google Chrome 55 (i.e. the latest stable version) on 64-bit SL7.0 using a 64-bit RPM. The problem is that google chrome starts fine (except for an SELinux-related issue which I fixed), but it closes without warning after about a minute. No indication of a crash is shown except for "Google Chrome cras...
I am unable to debug the problem with gdb (bt only gives me hexadecimal numbers, not function names). Since, for the severity of this bug, everyone using the current version should have been affected (Quite a number of people have this bug too, according to the bug tracker). Seeing that a few other people have this pr...
Google Chrome segmentation fault within a minute
1,477,625,022,000
I am having a problematic issue that I can't seem to figure out. I am able to open the settings as root user just fine. When I click on Users, nothing happens. I am running on Linux kali 4.7.0-kali1-amd64 #1 SMP Debian 4.7.6-1kali1 (2016-10-17) x86_64 GNU/Linux. This is what I get in /var/log/syslog Oct 27 21:00:09 ka...
I was unable to open the user settings as root. (Really, on a fresh install.) All I had to do was type useradd tempuser1 and then the reopen the user settings! I guess that my segfualt occurred because there were "no users" (because root doesn't count). I'm on the latest version of Kali.
Segfault trying to access Users in Settings
1,477,625,022,000
Installed mint-x-icons and mint-x-theme on a fresh Debian 8 testing running Cinnamon (v2.6.13). All themes options could be set to Mint-X, except for Controls. As soon as it was selected, the Themes window crashed and couldn't be opened again, nor cinnamon-settings in general. Nemo wouldn't start any longer either an...
The value to revert is org.cinnamon.desktop.interface.gtk-theme. It can be set back to Adwaita, Debian's Cinnamon default installation value from the terminal with gsettings set org.cinnamon.desktop.interface gtk-theme Adwaita or graphically with dconf Editor (dconf-editor package) setting the value Adwaita under org...
cinnamon-settings and Nemo crash with certain Cinnamon themes' contols on Debian 8
1,477,625,022,000
Lately my PC keeps getting segmentation fault, everywhere, on almost every apps (thunderbird, firefox, chromium, google-chrome, wine, byobu) here's the last few output of dmesg: [ 1474.815026] traps: chrome[2134] general protection ip:7f38bb407aef sp:7fff59358350 error:0 in chrome[7f38b9b18000+51d2000] [ 3867.645750] ...
Sounds like a hardware fault. Segfaults across the whole system can be caused by bad sectors on the disk or bad memory. Run a memory test and see if there's some faulty memory that is causing your issue. After that if the memory test does not find an issue, I would run a badblocks scan on your hard drive.
Segfault everywhere even when reinstalling the OS
1,477,625,022,000
I don't yet fully understand how segfaults and backtraces work, but I get the impression that if the function at the top of the list references "glib" or "gobject", you have Bad Issues(TM) with libraries that usually shouldn't go wrong. Well, that's what I'm getting here, from two completely different programs. The fi...
I get the impression that if the function at the top of the list references "glib" or "gobject", you have Bad Issues(TM) with libraries that usually shouldn't go wrong. You get the wrong impression, if you mean this indicates the flaw is probably in those libraries. It doesn't mean that; it more likely means that's...
Getting segmentation faults from inside glib and gobject - I THINK I want to build/statically link against an independant version of glib2
1,477,625,022,000
I was just experimenting with snapshots in LVM on Ubuntu 12.10. I created a snapshot logical volume of 6.5 GiB, and after making some changes to the origin decided to merge the snapshot back in to undo them. All seemed to be going well, but I noticed several LVM-related segfault messages in syslog. Commands entered: s...
Yeah it's definitely a bug but don't worry, LVM is smart enough to handle this stuff, I once had the power go out in the middle of a pvmove and all I had to do was basically get the server turned on again "cancel" the old pvmove and start it over it again. First off, it's important to know that the tools you use are j...
Should I be worried? Segfaults reported in syslog when merging LVM snapshot (reverting the original back to the snapshot)
1,477,625,022,000
I'm running Ubuntu 14.04 Trusty Tahr in a Microsoft Hyper-V virtual machine on Windows Server 2012 R2. I've stopped the VM, replaced an EXT4-formatted virtual disk volume (/dev/sdb) with a new (unformatted) disk volume and restarted the VM. I see the following messages: Filesystem check or mount failed. A maintenanc...
OP and I worked through this; see comments & chat for details. First, to find the problem process and location, this line in /etc/init/mountall-shell.conf /sbin/sulogin was changed to /usr/bin/ltrace -S -f -o /root/sulogin-ltrace.log /bin/sulogin Excerpt from log: 837 crypt("password", "x") = nil 837 strcmp(nil, "x"...
What Causes Maintenance Shell Segmentation Fault?
1,477,625,022,000
When I try to run any executable from my second (NTFS) drive, I get a segmentation fault. If I run the exact same executable from, for example, my home folder, it works just fine. For example: I compile the following C program using gcc a.c: #include <stdio.h> int main() { puts("Hello"); return 0; } Now I ru...
Note: I've written the individual fstab lines with 2 spaces between each and then spaced it out as best I could in the completed fstab at the bottom. Feel free to alter the mountpoint to match whatever location you're actually using Verification Install: sudo pacman -S ntfs-3g fuse Test Mount: sudo mkdir -p /mnt/ntf...
Segmentation fault when running binaries from second drive
1,477,625,022,000
I have a Dell, debian stable, laptop working with gnome environment. For several weeks Firefox crashed more and more often, resulting in mouse slows down during fews seconds, and then everything freezes, the laptop heats a lot, forcing me to hard reboot. I noticed that websites such as WhatsApp web or YouTube were spe...
The problem was actually an outdated BIOS, upgrading it solved almost everything. Noticed that there was also something wrong with libxul.so, everything was fine after I deleted and reinstalled it.
Seems that any JavaScript makes my debian laptop crash
1,477,625,022,000
I am trying to debug an issue that happens all the time. NetworkManager is running and upon connecting to a network, I am using a dispatcher script to setup my firewall rules (shorewall, and it is set to run asynchronously). As soon as shorewall sets up the rules, NetworkManager crashes: NetworkManager segfault at 8...
I reverted back to NetworkManager 1.4.4-r1 and the problem appears to go away. I will file a bug report with NetworkManager.
NetworkManager 1.10.2 segfaults when shorewall starts
1,477,625,022,000
When I run transmission-gtk on my Linux Mint, the window is shown as usual but suddenly it crashes. I tried transmission-gtk on terminal and the output was Segmentation fault. I didn't update or upgrade the system before this happened, but I did run sudo apt-get --purge autoremove once. How can I fix this?
You could try sudo dpkg-reconfigure transmission-gtk And, if that doesn't help, completely remove it and reinstall: sudo apt-get purge transmission-gtk && sudo apt-get install transmission-gtk This could also be caused by something in your user's settings. Try renaming transmission's configuration directory: mv ~/....
segmentation fault : transmission-gtk & transmission-qt in linux mint
1,477,625,022,000
A lot of the programs I use on my machine exit with segfaults. Nearly all programs function normally until being closed, at which point they segfault. So far the only two programs that have not worked because of this issue are VLC and Cinnamon, while many other programs like firefox and chromium are affected, but only...
I am using a Haswell CPU and thus had to install the updated microcode, wy installing the intel-ucode package.
Antergos libpthread causes segmentation faults
1,477,625,022,000
I have a program that throws a segmentation fault on certain circumstances. I want to execute a command when the segmentation fault occurs to process the data, then execute the command again, and keep doing so until the segmentation fault stops. As a rough attempt at pseudo code, dodgy_command while SegFault ...
When a program aborts abnormally the exit code (as seen by the shell) typically has the high bit set so the value is 128 or higher. So a simple solution might be dodgy_command while [ $? -ge 128 ] do process_data dodgy_command done If you specifically only want a segfault and not any other type of error, the wh...
Construct a while loop around a command throwing a segmentation fault
1,477,625,022,000
Segfault but why? It only happens with debian:stretch+mysql.connector+tox and Python3.x. Reproducible from just a few lines: FROM debian:stretch RUN apt update -y && apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-ut...
at first, it looks like a socket issue but socket.gethostbyname(host_name) works. after some digging, I find that the issue is isolated to " mysql-connector-python" if you change that to " mysql-connector-python-rf" in your tox.ini the error is gone. that means somewhere in mysql-connector-python it is unable to re...
Segfault with Debian Stretch
1,477,625,022,000
I am using Ubuntu 18.04.5. This very simple program segfaults on the invocation of rl_parse_and_bind. Can anyone help me? // Build with cc read.c -o read -lreadline #include <readline/readline.h> // apt install libreadline-dev int main() { rl_parse_and_bind("\"C-b\":history-search-backward"); char *input =...
This is because the readline library will actively modify that string using strtok, and the string you passed is a constant. Trying to write to it will result in a segmentation fault. Try: char *copy = strdup("\"C-b\":history-search-backward"); rl_parse_and_bind(copy); // free(copy); copy = NULL; // This to tidy up th...
readline's rl_parse_and_bind causes crash
1,477,625,022,000
After editing .bashrc I had "Segmentation fault" as an error. This is what I added to bashrc: if [ -f ~/.bashrc ]; then source ~/.bashrc fi # If not running interactively, don't do anything [ -z "$PS1" ] && return # some more ls aliases alias ll='ls -l' # enable programmable completion features (you don't need ...
At the beginning you are recursively sourcing ~/.bashrc. You probably wanted to include /etc/bashrc instead. As a result bash terminates with stack overflow during parsing.
Debian Segmentation Fault
1,626,441,116,000
Since I use microsoft teams on my Debian buster machine, I get a GUI freeze sometimes: The mouse pointer can still be moved on the screen, but no visible feedback on clicks or keyboard presses. Also no switching to a console with ctrlaltF1 I could not help myself other then sshing to the machine to restart Xorg. The d...
nouveau is known for being quite unstable and crash-prone, so I'd recommend installing NVIDIA proprietary drivers instead. The error you're getting indicates exactly that. Alternatively try installing a fresh kernel, 4.19 is quite dated and may not contain all the fixes the nouveau driver has seen.
MS teams makes the whole GUI stall: GpuWatchdog segfault
1,626,441,116,000
To the best of my knowledge, when a process writes to a file it starts a system call. Among the required information, it expects a pointer to a buffer in the user space, filled with the data to write. Consider a scenario where there is a process that spawns two threads. One thread executes a system call to write 10MB....
Currently, operations on a filesystem are un-interruptible - except for network filesystems. See TASK_KILLABLE [LWN.net, 2008]. For traditional block-based filesystems, you might predict your guarantee will be met. I don't believe TASK_KILLABLE has been adopted widely outside of network filesystems. However I would ...
An IO write operation can outlive a process?
1,626,441,116,000
I've got a device with bad RAM. Running memtest overnight shows all faulting addresses to be in the 0x7d0000000 - 0x7f0000000 range. I plan to replace the RAM, but until then, I've disabled a 2GB chunk around it with memmap=: # cat /proc/cmdline BOOT_IMAGE=/boot/vmlinuz-6.5.0-25-generic root=UUID=5277c53f-b2cd-4301-8f...
You're confusing address spaces here; this is virtual memory of the process address space of the udisks process. You reserved physical address spaces. A segfault happens when a process tries to access a virtual memory address that is not mapped to any physical page, or that it's not allowed to access. Physical and vir...
What does the "segfault at X" kernel log message mean if X is very large?
1,626,441,116,000
After resuming from a hybrid-sleep, I can log in (swaylock) and initially it seems ok - pwd, journalctl -xe run as expected in the shell still open from when I put it to sleep. After a short while though, tens of seconds, when I'd exited journalctl (I just wanted to confirm it had actually been asleep) CPU load increa...
I'm not sure of the precise cause; but the root of my problems ended up being that I hadn't booted with the resume & resume_offset kernel parameters. I had thought that these were only required on the resuming boot; not the boot that hibernates, but that seems not to be the case.
SIGSEGV address boundary error shortly after waking from sleep
1,626,441,116,000
I am trying to implement a PCI device driver for a virtual PCI device on QEMU. The device defines a BAR region as RAM, and the driver can do ioremap() this region and access it without any issues. The next step is to assign this region (or a fraction of it) to a user application. To do this, I have also implemented an...
I've solved this issue and managed to map PCI memory to userspace via the driver. I've changed the pfn input of the remap_pfn_range function I was using in my custom .mmap The original was: io_remap_pfn_range(vma, vma->vm_start, pfn, vma->vm_end - vma->vm_start, vma->vm_page_prot )) where the pfn was the result of th...
How can my PCI device driver remap PCI memory to userspace?
1,626,441,116,000
When selecting an image for upload, I am able to see the preview in the browser. Once the actual upload process begins, Chromium segfaults. Seems like it's some sort of odd permission issue? The file I'm trying to upload, is an image I had previously downloaded from another page using "Save As...". The picture is stor...
Update: The solution is odd, you need to go into Ubuntu Software, select Chromium, then permissions. All permissions will be selected on by default. Oddly enough, if you flip off the ones file access, then turn them back on, it will magically work. If you get issues with you Chromium after this, toggle them on/again, ...
Why does Chromium segfault when uploading images?
1,626,441,116,000
I am trying to compile dev-lang/yasm inside a funtoo chroot and consistently get segfaults. Any ideas what I should try: [Fri Jan 1 14:54:33 2016] re2c[14786]: segfault at 0 ip 00007f5ad4d4dd5b sp 00007ffe0c08b8c0 error 4 in libc-2.20.so[7f5ad4ce4000+193000] I am compiling on Fedora 23 as the libraries there seem t...
I believe it was a permissions issue on a hardened box. I was extracting some configuration files via tar and overwrote the permissions on some directories hence creating the problem.
libc segfaults while compiling dev-lang/yasm
1,626,441,116,000
this problem occurs on Debian jessie x86 with systemd. It leads to an incomplete boot sequence on init 2 because network-manager won't start. it leaves the whole system unusable NetworkManager[785]: segfault at e7394845 ip b74ab7a1 sp b7548810 error 7 in libgnutls-deb0.so.28.41.0[b746f000+13a000]
Turned out, I interrupted an upgrade process earlier. I manually reinstalled the network manager package.
segfault in libgnutls - Debian won't complete boot
1,626,441,116,000
Debian stretch user here. I wanted a screen flash every ten minutes. After trying a couple of alternatives (includeing xrefresh) I decided to use sct. It works in shell but does not work with cron. This works: sct 2000 The script: (named colrefr) #!/bin/bash PATH=/usr/bin sct 2000; sleep 3; sct Cron: (pgrep cron show...
This is a combination of two things: You have not told the program where your X server is. M. Unangst's program does no error checking and handling at all. The program needs to inherit a DISPLAY environment variable, specified in your crontab or in a wrapper script, to tell it where the X server display that you wan...
sct (setcolortemperature) segfaults with cron
1,626,441,116,000
I'm reading about the x86, In that they have mentioned segment size can go upto 4GB (in 32-bit) architecture. Does anybody knows or experienced the segment size going beyond limit? Or upto what limit segment size goes in practical life? and If it goes beyond the max limit then, it is breaked into segments of diff...
The operating system will not use more memory than it can handle in its allocation table. Since the maximum number of bytes that can be represented with 32 bits is 4 294 967 296, that limits the memory to 4GB. On 64 bit systems, the maximum would therefore be 18 446 744 073 709 551 616 bytes (16 777 216 TB) which w...
What is maximum size of any memory segment goes in real life coding?
1,327,107,993,000
I notice that some scripts which I have acquired from others have the shebang #!/path/to/NAME while others (using the same tool, NAME) have the shebang #!/usr/bin/env NAME. Both seem to work properly. In tutorials (on Python, for example), there seems to be a suggestion that the latter shebang is better. But, I don'...
Objective Criteria/Requirements: In determining whether to use an absolute or logical (/usr/bin/env) path to an interpreter in a shebang, there are two key considerations: a) The interpreter can be found on the target system b) The correct version of the interpreter can be found on the target system If we AGREE that "...
Why is it better to use "#!/usr/bin/env NAME" instead of "#!/path/to/NAME" as my shebang?
1,327,107,993,000
This may be a silly question, but I ask it still. If I have declared a shebang #!/bin/bash in the beginning of my_shell_script.sh, so do I always have to invoke this script using bash [my@comp]$bash my_shell_script.sh or can I use e.g. [my@comp]$sh my_shell_script.sh and my script determines the running shell usin...
The shebang #! is an human readable instance of a magic number consisting of the byte string 0x23 0x21, which is used by the exec() family of functions to determine whether the file to be executed is a script or a binary. When the shebang is present, exec() will run the executable specified after the shebang instead. ...
Does the shebang determine the shell which runs the script?
1,327,107,993,000
I've created a bash script but when I try to execute it, I get #!/bin/bash no such file or directory I need to run the command: bash script.sh for it to work. How can I fix this?
This kind of message is usually due to a buggy shebang line, either an extra carriage return at the end of the first line or a BOM at the beginning of it. Run: $ head -1 yourscript | od -c and see how it ends. This is wrong: 0000000 # ! / b i n / b a s h \r \n This is wrong too: 0000000 357 2...
#!/bin/bash - no such file or directory
1,327,107,993,000
I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!). I use NixOS, and the first part of the shebang in any script I write is usually /usr/bin/env. The problem I encounter then is that everything that comes after is interpreted as a single file or direct...
There is no general solution, at least not if you need to support Linux, because the Linux kernel treats everything following the first “word” in the shebang line as a single argument. I’m not sure what NixOS’s constraints are, but typically I would just write your shebang as #!/bin/bash --posix or, where possible, s...
Multiple arguments in shebang
1,327,107,993,000
If you create an executable file with the following contents, and run it, it will delete itself. How does this work? #!/bin/rm
The kernel interprets the line starting with #! and uses it to run the script, passing in the script's name; so this ends up running /bin/rm scriptname which deletes the script. (As Stéphane Chazelas points out, scriptname here is sufficient to find the script — if you specified a relative or absolute path, that's pa...
Why does the following script delete itself?
1,327,107,993,000
I'm confused about following script (hello.go). //usr/bin/env go run $0 $@ ; exit package main import "fmt" func main() { fmt.Printf("hello, world\n") } It can execute. (on MacOS X 10.9.5) $ chmod +x hello.go $ ./hello.go hello, world I haven't heard about shebang starting with //. And it still working when I i...
It isn't a shebang, it is just a script that gets run by the default shell. The shell executes the first line //usr/bin/env go run $0 $@ ; exit which causes go to be invoked with the name of this file, so the result is that this file is run as a go script and then the shell exits without looking at the rest of the ...
Shebang starting with `//`?
1,327,107,993,000
In most shell scripts I've seen (besides ones I haven't written myself), I noticed that the shebang is set to #!/bin/sh. This doesn't really surprise me on older scripts, but it's there on fairly new scripts, too. Is there any reason for preferring /bin/sh over /bin/bash, since bash is pretty much ubiquitous, and ofte...
There are systems not shipping bash by default (e.g. FreeBSD). Even if bash is installed, it might not be located in /bin. Most simple scripts don't require bash. Using the POSIX shell is more portable and the scripts will run on a greater variety of systems.
Is there any reason to have a shebang pointing at /bin/sh rather than /bin/bash?
1,327,107,993,000
(See Use #!/bin/sh or #!/bin/bash for Ubuntu-OSX compatibility and ease of use & POSIX) If I want my scripts to use the Bash shell, does using the .bash extension actually invoke Bash or does it depend on system config or the first shebang line. If both were in effect but different, which would have precedence? I'm no...
does using the .bash extension actually invoke bash or does it depend on system config / 1st shebang line. If you do not use an interpreter explicitly, then the interpreter being invoked is determined by the "shebang" used in the script (the #!-line, which must be the first line of the script file). On the other han...
Use .sh or .bash extension for Bash scripts?
1,327,107,993,000
So, I thought I had a good understanding of this, but just ran a test (in response to a conversation where I disagreed with someone) and found that my understanding is flawed... In as much detail as possible what exactly happens when I execute a file in my shell? What I mean is, if I type: ./somefile some arguments in...
The definitive answer to "how programs get run" on Linux is the pair of articles on LWN.net titled, surprisingly enough, How programs get run and How programs get run: ELF binaries. The first article addresses scripts briefly. (Strictly speaking the definitive answer is in the source code, but these articles are easie...
What exactly happens when I execute a file in my shell?
1,327,107,993,000
Can I assume that enough people have zsh installed to run scripts with a #!/usr/bin/env zsh as shebang? Or will this make my scripts un-runnable on too many systems? Clarification: I’m interested in programs/scripts an end user might want to run (like on Ubuntu, Debian, SUSE, Arch &c.)
For portability, no. While zsh can be compiled on any Unix or Unix-like and even Windows at least via Cygwin, and is packaged for most Open Source Unix-likes and several commercial ones, it is generally not included in the default install. bash on the other end is installed on GNU systems (as bash is the shell of the ...
Is it recommended to use zsh instead of bash scripts? [closed]
1,327,107,993,000
I want to run a bash script in a detached screen. The script calls a program a few times, each of which takes too long to wait. My first thought was to simply open a screen and then call the script, but it appears that I can't detach (by ctrl-a d) while the script is running. So I did some research and found this inst...
The shebang line you've seen may work on some unix variants, but not on Linux. Linux's shebang lines are limited: you can only have one option. The whole string -d -m -S screenName /bin/bash is passed as a single option to screen, instead of being passed as different words. If you want to run a script inside screen an...
Run script in a screen
1,327,107,993,000
Is it possible to have a shebang that, instead of specifying a path to an interpreter, it has the name of the interpreter, and lets the shell find it through $PATH? If not, is there a reason why?
PATH lookup is a feature of the standard C library in userspace, as are environment variables in general. The kernel doesn't see environment variables except when it passes over an environment from the caller of execve to the new process. The kernel does not perform any interpretation on the path in execve (it's up to...
Why not use pathless shebangs?
1,327,107,993,000
Simple inquiry: I have just realized that I have never seen a shebang on top of a .bashrc script, which leads me to think the system uses the default shell to source it upon login (${SHELL}). I am pondering over reasons why that is the case, i.e. is it considered a bad habit to use something other than the default s...
.bashrc and .bash_profile are NOT scripts. They're configuration file which get sourced every time bash is executed in one of 2 ways: interactive login The INVOCATION section of the bash man page is what's relevent. A login shell is one whose first character of argument zero is a -, or one started with the --logi...
Why no shebang in .bashrc/.bash_profile?
1,327,107,993,000
Suppose the default shell for my account is zsh but I opened the terminal and fired up bash and executed a script named prac002.sh, which shell interpreter would be used to execute the script, zsh or bash? Consider the following example: papagolf@Sierra ~/My Files/My Programs/Learning/Shell % sudo cat /etc/passwd | gr...
Because the script does not begin with a #! shebang line indicating which interpreter to use, POSIX says that: If the execl() function fails due to an error equivalent to the [ENOEXEC] error defined in the System Interfaces volume of POSIX.1-2008, the shell shall execute a command equivalent to having a shell invoked...
Which shell interpreter runs a script with no shebang?
1,327,107,993,000
Does "shebang" mean "bang she"? Why not "hebang" as "bang he"?
Another interesting name derivation from here. Among UNIX shell (user interface) users, a shebang is a term for the "#!" characters that must begin the first line of a script. In musical notation, a "#" is called a sharp and an exclamation point - "!" - is sometimes referred to as a bang. Thus, shebang becomes ...
Why is "shebang" called "shebang"?
1,327,107,993,000
In the Apache httpd project's "support/apxs.in" script, a text surrounded with @ signs comes after #!. That is, the first line of the script is: #!@perlbin@ -w Is this a Perl thing or a UNIX kernel thing? In other words, it it possible to execute this script using path/to/script/script_name.in? If not, then what is t...
This looks like a placeholder in an GNU Automake template which is going to be filled in by a configure script. So it's neither a Perl or Unix kernel thing, but a GNU autotools thing. It is probably from a file in a source distribution, not from a file that was installed on the system through make install or a package...
At sign after shebang?
1,327,107,993,000
Is there any way to dynamically choose the interpreter that's executing a script? I have a script that I'm running on two different systems, and the interpreter I want to use is located in different locations on the two systems. What I end up having to to is change the hashbang line every time I switch over. I would l...
No, that won't work. The two characters #! absolutely needs to be the first two characters in the file (how would you specify what interpreted the if-statement anyway?). This constitutes the "magic number" that the exec() family of functions detects when they determine whether a file that they are about to execute is...
Choose interpreter after script start e.g. if/else inside hashbang
1,327,107,993,000
I recently noticed that many scripts are using /usr/bin/env in their shebang. I have seen that mainly using Bash and Python, but thus far never in conjunction with POSIX sh (ash, dash,...). I wonder why, and if my, meant-to-be highly portable, POSIX shell scripts might benefit from the env approach? Is there a genera...
Setting to #!/bin/sh will go directly to that file /bin/sh. Setting to #!/usr/bin/env sh will execute /usr/bin/env with an argument of sh. This will cause the script to be executed by sh in your PATH variable rather than explicitly with /bin/sh.
POSIX shell scripts shebang #!/bin/sh vs #!/usr/bin/env sh, any difference?
1,327,107,993,000
I ran into some issues when running some installation scripts where they complained of bad interpreter. So I made a trivial example but I can't figure out what the problem is, see below. #!/usr/bin/env bash echo "hello" Executing the script above results in the following error [root@ech-10-24-130-154 dc-user]# ./junk...
ls -lL /usr/bin/env shows that the symbolic link is broken. That explains why the shebang line isn't working: the kernel is trying, and obviously failing, to execute a dangling symbolic link. /usr/bin/env -> ../../bin/env is correct if /usr and /usr/bin are both actual directories (not symlinks). Evidently this isn't ...
Why is #!/usr/bin/env bash not working on my system?
1,327,107,993,000
What does the eu mean after #!/bin/bash -eu at the top of a bash script? Normally I begin my bash scripts with this hashbang/shebang: #!/bin/bash but I just came across one with #!/bin/bash -eu and I have no idea why there is a -eu there. Reading the man bash pages doesn't seem to help me, but maybe I'm overlooking ...
They're the same options as -e and -u to the set builtin. They can be given on the shell command line too, and they get given as command line arguments from the hashbang line too. (But note e.g. issues with Multiple arguments in shebang) The online manual says, under "Invoking Bash", that All of the single-character ...
What does the `-eu` mean in `#!/bin/bash -eu` at the top of a bash script? (or any of `-abefhkmnptuvxBCHP`)
1,327,107,993,000
From the Shell Command Language page of the POSIX specification: If the first line of a file of shell commands starts with the characters "#!", the results are unspecified. Why is the behavior of #! unspecified by POSIX? I find it baffling that something so portable and widely used would have an unspecified behavior...
I think primarily because: the behaviour varies greatly between implementation. See https://www.in-ulm.de/~mascheck/various/shebang/ for all the details. It could however now specify a minimum subset of most Unix-like implementations: like #! *[^ ]+( +[^ ]+)?\n (with only characters from the portable filename charact...
Why is the behavior of the `#!` syntax unspecified by POSIX?
1,327,107,993,000
I've always heard that the target of a shebang line (e.g. #!/bin/bash) must be a binary executable, not a script. And this is still true for many OSes (e.g. MacOS). But I was surprised to see that this is not true on Linux, where up to 4 levels of scripts can be used, where the fourth script references a binary exec...
According to Sven Mascheck (who's generally reliable and well-informed): interpreter itself as #! script or: can you nest #!? (…) Linux since 2.6.27.9 2 and Minix accept this. (…) see the kernel patch (patch to be applied to 2.6.27.9) and especially see binfmt_script.c which contains the important parts. Linux allows...
Shebang can reference a script in Linux
1,327,107,993,000
Which one is better: #!/usr/bin/env sh #!/bin/sh empty/no header I used to think the 1st one is the best, anyway i've found on some Linux-based systems (like Android) that pathname is missing, so now i'm thinking the only way to have "portable" shell scripts is to not include any header...
For portability, you can safely assume that #!/bin/sh will find a mostly POSIX-compliant shell on any standard Unix or Linux system, but that's really about it. In FreeBSD, OpenBSD and NetBSD (along with DragonFly, PC-BSD and some other derivatives), bash is located at /usr/local/bin/bash (if it is installed), so the ...
shell script header for best compatibility [duplicate]
1,327,107,993,000
Is gawk in /bin or /usr/bin usually? I would go with #!/usr/bin/env gawk but then I can't use arguments. Right now I'm using #!/bin/gawk -f. The script is very long and contains a lot of single quotes and works with stdin. The GNU Awk manual has section 1.1.4 Executable awk Programs where it uses #!/bin/awk in its ex...
Shebang wasn't meant to be that flexible. There may be some cases where having a second parameter works, I think FreeBSD is one of them. gawk and most utilities that come with the OS are expected to be in /usr/bin/. In the older UNIX days, it was common to have /usr/ mounted over NFS or some less expensive media to s...
Distributing a script: Should I use /bin/gawk or /usr/bin/gawk for shebang?
1,327,107,993,000
When I run this script, intended to run until killed... # foo.sh while true; do sleep 1; done ...I'm not able to find it using ps ax: >./foo.sh // In a separate shell: >ps ax | grep foo.sh 21110 pts/3 S+ 0:00 grep --color=auto foo.sh ...but if I just add the common "#!" header to the script... #! /usr/bin/b...
When the current interactive shell is bash, and you run a script with no #!-line, then bash will run the script. The process will show up in the ps ax output as just bash. $ cat foo.sh # foo.sh echo "$BASHPID" while true; do sleep 1; done $ ./foo.sh 55411 In another terminal: $ ps -p 55411 PID TT STAT TIM...
Why doesn't "ps ax" find a running bash script without the "#!" header?
1,327,107,993,000
I have a project comprised of about 20 small .sh files. I name these "small" because generally, no file has more than 20 lines of code. I took a modular approach because thus I'm loyal to the Unix philosophy and it's easier for me to maintain the project. In the start of each .sh file, I put #!/bin/bash. Simply put, I...
Even though your project may now be solely consisting of 50 Bash scripts, it will sooner or later start accumulating scripts written in other languages such as Perl or Python (for the benefits that these scripting languages have that Bash does not have). Without a proper #!-line in each script, it would be extremely d...
Too many shebang (script declaration) lines --- any way to reduce their amount?
1,327,107,993,000
I'm trying to run a python script, on a headless Raspberry PI using winSCP and get the following error message: Command '"./areadetect_movie_21.py"' failed with return code 127 and error message /usr/bin/env: python : No such file or directory. When I try and run from terminal, I get: : No such file or directory. I ...
From AskUbuntu, answer by Gilles: If you see the error “: No such file or directory” (with nothing before the colon), it means that your shebang line has a carriage return at the end, presumably because it was edited under Windows (which uses CR,LF as a line separator). The CR character causes the cursor to move back...
No such file or directory but I can see it!
1,327,107,993,000
I'm on a kali linux 64 bit. I have created a python script which takes 2 arguments to start. I don't want to type out every time the exact same paths or search in the history of the commands I used in terminal. So I decided to create a simple script which calls the python script with its arguments. #! /bin bash pyt...
You have a space instead of a forward slash here: #! /bin bash Should be: #! /bin/bash or simply #!/bin/bash (the first space is optional).  The shebang (#!) should be followed by the path to an executable, which may be followed by one argument, e.g., #!/usr/bin/env sh In this case /usr/bin/env is the executable;...
Bash Script Permission denied & Bad Interpreter
1,327,107,993,000
I have a growing collection of scripts which should be sourced, not run. At the moment they have the shebang #! /bin/cat but I would prefer the have them be sourced into bash when run, in the same way as I had done $ . /path/to/script.sh or $ source /path/to/script.sh But . and source are bash builtins, so is an al...
No. By the time a shebang comes into play, you have already lost. A shebang is applied when a process is exec()'d and typically that happens after forking, so you're already in a separate process. It's not the shell that reads the shebang, it's the kernel.
Can I use a shebang to have a file source itself into current bash environment?
1,327,107,993,000
Why does the "she-bang" begin with a #!, like #!/bin/bash? I have always accepted that this how it is done, but is there a reason behind it? Why start with #; isn't that usually a comment? Or is it the point that it should be comment?
Typically shebang refers to just the #! (! is typically called "bang", and it looks like "she" is a corruption of either "SHArp" or "haSH" for #) -- the whole line is called a shebang line It does intentionally start with a comment character for backwards-compatibility with things that don't know how to handle it; the...
Why does the "she-bang" begin with a "#!"?
1,327,107,993,000
I read in another answer that I'm not able to pass arguments to the interpreter than I'm giving to /usr/bin/env: Another potential problem is that the #!/usr/bin/env trick doesn't let you pass arguments to the interpreter (other than the name of the script, which is passed implicitly). However, it looks like I am ab...
Some Unices, most notably the macOS (and up until 2005, FreeBSD), will allow for this, while Linux will not, but... If one use the env utility from a recent release of the GNU coreutils package (8.30+), it has a non-standard -S option that allows for supplying multiple arguments in #! lines. The opposite question: She...
Why am I able to pass arguments to /usr/bin/env in this case?
1,327,107,993,000
I recently came up to an easy fix for a crontab logging issue and I am wondering what are the pro's and con's of using this specific fix (running a script with a "login shell flag"), as: #!/bin/bash -l
[The following assumes that your unspecified "logging issue" was related to missing environment setup, normally inherited from your profile.] The -l option tells bash to read all the various "profile" scripts, from /etc and from your home directory. Bash normally only does this for interactive sessions (in which bash ...
What are the pro's and con's in using the "-l" in a script shebang
1,327,107,993,000
I have a script containing: #!/bin/bash printenv When I run it from the command line: env testscript.sh bash testscript.sh sh testscript.sh every time, it outputs SHELL=/bin/bash. However, when it is run from the cron, it always outputs SHELL=/bin/sh. Why is this? How can I make cron apply the shebang? I already che...
The shebang is working and cron has nothing to do with that. When a file is executed, if that file's content begins with #!, the kernel executes the file specified on the #! line and passes it the original file as an argument. Your problem is that you seem to believe that SHELL in a shell script reflects the shell tha...
Shebang does not set SHELL in cron
1,327,107,993,000
I have a file named test.sh: #!/bin/bash -o pipefail echo "Running test" git diff HEAD^ HEAD -M --summary | grep delete | cut --delimiter=' ' -f 5 When I try to run this script as: ./test.sh I get: /bin/bash: line 0: /bin/bash: ./test: invalid option name I ran cat -v test.sh to check if there are carriage retur...
The Linux kernel treats everything following the first “word” in the shebang line as a single argument. One solution is to set -o later in the script: #!/bin/bash set -o pipefail echo "Running test" git diff HEAD^ HEAD -M --summary | grep delete | cut --delimiter=' ' -f 5
Invalid option name error with shebang "#!/bin/bash -o pipefail" in script [duplicate]
1,327,107,993,000
Say I have a file hello: #!/bin/sh echo "Hello World!" Provided the executable bit is set on that file, I can execute it by entering its path on the prompt: $ ./hello Hello World! Is there a more explicit equivalent to the above? Something akin to: $ execute hello I know I can pass hello as an argument to /bin/sh,...
You can use perl: perl hello From perl docs: If the #! line does not contain the word "perl" nor the word "indir", the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #!, because they can tell a program that their SHELL ...
Equivalent of executing a file (with shebang line) by entering its path?
1,327,107,993,000
I have a script from other person which has a look (note: it's a single file): #!/bin/bash some commands some commands #!/bin/bash some commands some commands #!/bin/bash some commands some commands I wondering what is the purpose of second and third shebangs? Is it by mistake or on purpose?
If these lines are not the beginning of included shell scripts to be built, i.e. inside a scheme of the form: cat <<end_of_shell_script >dynamically_built_shell #!/bin/bash [...] end_of_shell_script Then the repeated construct you found is the result of many copy - paste of full shell scripts but without enough care ...
Multiple shebangs in a single bash file
1,327,107,993,000
I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, and using Homebrew (http://mxcl.github.io/homebrew/) can install GNU sed as gsed with the coreutils package, located at ...
There are a few options: Use #!/usr/bin/gsed -f (assuming it is in /usr/bin) as the shebang everywhere, and make sure that your Linux environments symlink this properly; Remove the GNUisms; Symlink sed to /usr/bin/gsed from a directory that earlier than /usr/bin in the user's $PATH (possibly dangerous); Make a wrappe...
How to share a GNU sed script between Linux and Mac OS X
1,327,107,993,000
I have downloaded this script named, pyAES.py and put it in a folder name codes, inside a Desktop directory of my Linux, According to this example, http://brandon.sternefamily.net/2007/06/aes-tutorial-python-implementation/ When I type, ./pyAES.py -e testfile.txt -o testfile_encrypted.txt the file pyAES.py should be...
It seems you have a badly-written shebang line. From the error you're getting: -bash: /usr/bin/pyAES.py: /usr/bin/python2: bad interpreter: No such file or directory I'd say you should set the first line of /usr/bin/pyAES.py to #!/correct/path/to/python where the /correct/path/to/python can be found from the output ...
Running python script from Linux Terminal
1,327,107,993,000
In the Pyenv project, we've had a peculiar problem. We are substituting python (and python*) with our Bash scripts ("shims") that select a Python executable to run at runtime. Now, some users wish to use a special selection logic when a Python script is run as path/to/script.py. The problem is, this logic should NOT a...
Since shebang is a Linux kernel feature -- maybe it sets some indicator that this mechanism has been used? Yes, it does. Linux sets the AT_EXECFN auxiliar vector entry to the path of the original executable. In C, you can do it with char *at_execfn = (char*)getauxval(AT_EXECFN), followed by stat(at_execfn), etc. Get...
Detect if a script is being run via shebang or was specified as a command line argument
1,327,107,993,000
All my Python and Perl scripts are simply NOT iterpreted via shebang. Never. But they work as expected when I explicitly call the binary. I double checked my Perl and Python installations, it is just too strange: they shebang-way execution works very well in the target system chroot on a sane host but not in the actu...
Your kernel was compiled without CONFIG_BINFMT_SCRIPT=y. This setting controls shebang support. From make menuconfig: Symbol: BINFMT_SCRIPT [=y] Type : tristate Prompt: Kernel support for scripts starting with #! ...
Perl and Python wrongly interpreted via shebang on Linux
1,584,914,963,000
I am on Linux Mint 19.03. I have a setup shell script file, setup.sh. When I run ./setup.sh muyustan@mint:~/Downloads/quartusExtracted$ ./setup.sh bash: ./setup.sh: /bin/env: bad interpreter: No such file or directory The shebang in setup.sh: #!/bin/env bash My understanding of these things are very narrow, since I...
Nothing is wrong with your system, you're just using the wrong path to env. On Linux systems, at least, the env binary is normally in /usr/bin and not /bin: $ type env env is /usr/bin/env So, your script is telling your system to use /bin/env, which doesn't exist, and that's why you're getting that error. Simply chan...
/bin/env : bad interpreter
1,584,914,963,000
I'm writing a script to test a shell project to see that my custom shell has correct output. str="HELLO" echo $str echo "*** YOU SHOULD SEE HELLO ABOVE ***" ls * echo "*** YOU SHOULD SEE THE OUTPUT FROM ls * ABOVE ***" who|awk '{print $1}' echo "*** YOU SHOULD SEE THE OUTPUT FROM who ABOVE ***" echo $((1+2*3-4/5+6*7-...
It should be #!/usr/local/bin/osh if your shell is in /usr/local/bin. If /usr/local/bin is on your PATH then #!/usr/bin/env osh should work too... (In fact that's the only point of env here — it will find osh wherever it's installed, as long as it's on the PATH, so it doesn't matter if it's in /usr/local/bin, /usr/b...
How should I handle the shebang when writing my own shell?
1,584,914,963,000
I notice that with bash scripts, some people use a different shebang to the one that I'm used to putting at the top of my own. Can someone simplify the difference between these two? I use the #!/bin/bash one all the time. #!/bin/bash #!/usr/bin/env bash
The #!/usr/bin/env bash results in the script using whatever bash is found first in $PATH. While it is common for bash to be located at /bin/bash. There are cases where it is not (different operating systems). Another potential use is when there are multiple bash shells installed (newer version at an alternate locatio...
What is the difference in these two bash environments?
1,584,914,963,000
I'm developing a perl script which expected to be downloaded by Mac users with a very small knowledge of shell, linux etc, let's say office managers and accountants. After the downloading the script should be executed just by double-clicking via GUI. My goal is to make this as painless as possible to non-tech-savvy u...
Or, you can have sh take care of it for you: #!/bin/sh exec perl -x "$0" "$@" #!/usr/bin/perl ... Yes, that's sh and Perl all in one file. From man perlrun: -x tells Perl that the program is embedded in a larger chunk of unrelated text, such as in a mail message. Leading garbage will ...
run perl script with unknown perl location
1,584,914,963,000
I have a Makefile, and I want make to run automatically when I double-click it (from the Ubuntu file manager). So, I made this Makefile executable, and added at its top the following shebang line: #!/usr/bin/make -f When I run /usr/bin/make -f Makefile, I get the desired result. However, when I double-click the Makef...
#!/usr/bin/make -f is a valid shebang to allow execution of a Makefile. The problem with your Makefile isn’t its shebang, it’s that it uses Windows line-endings; if you fix that, e.g. with sed -i $'s/\r$//' Makefile your Makefile will run correctly. The difference between using make to run such a Makefile, and runnin...
How to make a Makefile executable?
1,584,914,963,000
I was looking up shebang and wondering why I would use it. I could execute a bash script using: bash foo.sh or ./foo.sh (with a shebang line in foo.sh) What are the pros and cons of each and which one should I use by default?
I would say yes, it's intrinsically better to use a shebang. Pro: If you put all your scripts in your $PATH (maybe /usr/local/bin or ~/bin) and mark them as executable, then you can execute them by name without thinking about which interpreter you need to invoke (bash, Python, Ruby, Perl, etc.). If you place an execu...
Is it better to use a shebang line to execute a script?
1,584,914,963,000
I want to find out all scripts with a specific shebang line. Specifically, I want all files that match the following criteria: It's mostly a plain text file (stuffs created by gzexe don't look very friendly) The 1st line contains solely #!/bin/sh or #! /bin/sh (with a space) I would like to do this with find, ...
If you have GNU grep grep -rIzl '^#![[:blank:]]*/bin/sh' ./
Find all scripts with a given shebang line with find & sed
1,584,914,963,000
I have the following script in an executable file test-shebang.mjs and I wanted to use zx to run my script but have my ~/.zshrc be sourced before that: #!/usr/bin/env -S zsh -c 'source ~/.zshrc; zx --install $@' -- console.log("work pls") ./test-shebang.mjs works fine in Ubuntu: ❯ cat /etc/os-release PRETTY_NAME="Ub...
Shebang lines are parsed slightly differently on different Unix kernels. On Linux and on modern BSD, the command is followed by a single argument (or none), which can contain spaces. On macOS, the command is followed by zero or more arguments separated by spaces. So on Linux, when you run ./test-shebang.mjs with the a...
Why does env -S with quoted strings in the shebang line work fine in Ubuntu but not in macOS?
1,584,914,963,000
#!python3 print("Hello") I find that this code works fine in my terminal. But everyone does #!/path/to/file or #!/usr/bin/env command. Is there any reason to avoid using #!command in shebang lines?
A path-less shebang assumes that the command in the shebang is in the current directory, in the general case. More generically, a non-absolute shebang is interpreted relative to the current directory of the process executing the script. Path-less shebangs where the command isn’t in the current directory work only when...
Why don't we use #!command for the shebang line?
1,584,914,963,000
If the current user only has execute (--x) permissions on a file, under which user does the interpreter (specified by #!/path/to/interpreter at the beginning of the file) run? It couldn't be the current user, because he doesn't have permission to read the file. It couldn't be root, because then arbitrary code included...
If the user has no read permission on an executable script, then trying to run it will fail, unless she has the CAP_DAC_OVERRIDE capability (eg. she's root): $ cat > yup; chmod 100 yup #! /bin/sh echo yup ^D $ ./yup /bin/sh: 0: Can't open ./yup The interpreter (whether failing or successful) will always run as the cu...
Who runs the interpreter for files that are execute-only?
1,584,914,963,000
A shebang (#!/bin/sh) is placed on the first line of a bash script, and it's usually followed on the second line by a comment describing what action the script performs. What if, for no particular reason, you decided to place the first command far beneath the shebang and the comment by, say, 10000 lines. Would that sl...
To find out, I created two shell files. Each starts with a shebang line and ends with the sole command date. long.sh has 10,000 comment lines while short.sh has none. Here are the results: $ time short.sh Wed Nov 12 18:06:02 PST 2014 real 0m0.007s user 0m0.000s sys 0m0.004s $ time long.sh Wed Nov 12 18:...
Distance of a command from a shebang?
1,584,914,963,000
I'm looking for what to put on my_zsh_script.sh's "shebang line" that would have the same effect, portably, as $SHELL my_zsh_script.sh IOW, I looking for the valid equivalent of #!$SHELL or #!/usr/bin/env $SHELL (In some systems, my value for $SHELL is a version of zsh that, under some circumstances, differs fr...
#!/bin/sh my_script(){ { cat; cat <&3; }>"$0" } <<SHEBANG 3<<\SCRIPT #!${SHELL} SHEBANG #now all the rest of your script #goes in here SCRIPT my_script most shells will put all of the contents of here-documents in secure temp files automatically. those that don't use pipes, and those buffers are usually more t...
Shebang line for "run with $SHELL"
1,584,914,963,000
I want to use a program in the shebang, so I create a script named <myscript> with: #!<mypgm> I also want to be able to run <mypgm> directly from the command prompt. <mypgm> args... So far, no issue. I want to be able to run <myscript> from the command prompt with arguments. <myscript> blabla In turn, the shebang m...
Just realized that the following environment variable does it all: $_ When launched using <myscript>, its value is './<myscript>' When launched using <mypgm> <myscript> its value is the full path to <mypgm>. That simple, in my case: #!/bin/bash how_called=$_ if [[ "X$how_called" == X$0 || "X$how_called" ==X$BASH ]];...
shebang or not shebang
1,584,914,963,000
I have (foolishly?) written a couple of moderately general-purpose xslt scripts. I'd quite like to turn these into executables that read an xml document from standard in or similar. The way you do this with other languages is to use a shbang. Is there an easy / standard way to do this with xsltproc and friends? Sure...
You could use the generic binfmt-misc kernel module that handles which interpreter is used when an executable file is run. It is typically used to allow you to run foreign architecture files without needing to prefix them with qemu or wine, but can be used to recognise any magic characters sequence in a file header, o...
xslt shbang: Using xslt from the command line
1,584,914,963,000
I'd like to be able to run a script as another user, and only as that user. The way I currently have this set up is to have alice ALL = (bob) NOPASSWD: /home/alice/script.sh in the sudoers file and alice@foo:~$ ls script.sh -rwxr-xr-x 1 root root ..... script.sh alice@foo:~$ lsattr script.sh ----i----------- scr...
Linux (like many other Unix variants) only supports passing a single argument to the interpreter of a script. (The interpreter is the program on the shebang line.) A script starting with #!/usr/bin/sudo -u bob -- /bin/bash is executed by calling /usr/bin/sudo with the arguments -u bob -- /bin/bash and /home/alice/scri...
`sudo -u user` in shebang line
1,584,914,963,000
I'm trying to figure out exactly what the semantics of the shebang are. I can write a script like this: #!/usr/bin/env bash if [ -z "$FOO" ] then echo "No FOO" else echo "$FOO" fi without $FOO in my environment, and run it like ./foo.sh, bash foo.sh, env bash foo.sh, etc and it will print "No FOO" as expecte...
Most systems accept only up to one argument after the path of the interpreter in the shebang line. If you provide more than one, the behaviour depends on the system. On Linux, all of what's after the interpreter (without leading and trailing space or tab characters) is passed as a single argument. So with a she-bang o...
#!/usr/bin/env hangs with NAME=VALUE
1,584,914,963,000
Can I get arguments that happen to be AWK options passed directly to a pure AWK script? Example script: #!/usr/bin/env -S awk -f BEGIN { if (ARGV[1] == "-h") print "whoop" } I want ./myscript -h to print whoop. But AWK gets the -h first and prints its usage instead. Running ./myscript -- -h works but I can't get -- w...
For the sake of the challenge, it could be done with the FreeBSD env or with GNU env >= 8.30 (already assumed by the OP) in a shebang: #! /usr/bin/env -S sh -c 'exec awk -f "$0" -- "$@"' BEGIN { for(i = 1; i < ARGC; i++) print ARGV[i] } ./myscript -h 1 2 3 -h 1 2 3 It doesn't mean that it's a good idea, though. You ...
Pass options to AWK script bypassing AWK
1,584,914,963,000
I have tried migrating the shebang for my bash scripts from #!/bin/bash to #!/usr/bin/env bash, and some of them were broken because they relied on this code that checks for existing instances of themselves runnning, and which works only with #!/bin/bash: $ pidof -x myscript -o %PPID What I would like to know is how ...
On Linux, you could use pgrep to get PIDs of likely suspects, and inspect the first argument of those PIDs (available in /proc/$PID/cmdline). /proc/$PID/cmdline has all the arguments (including argument 0) of the process, separated ASCII NUL (\0). Something like: pgrep bash | xargs -I {} sed -nz '2{p; q}' /proc/{}/cmd...
See if a script is running when using #!/usr/bin/env
1,584,914,963,000
I would like to put shebang #!/bin/sh -eufo pipefail in my script. But there're several things strange: The script would fail with that shebang in FreeBSD but not when run on MacOS on FreeBSd, the same shebang works when directly executed from command line (also /bin/sh). >>> sh -eufo pipefail -c 'echo hi' # this w...
MacOS still retains the old FreeBSD behaviour from before 2005. In 2005, there was a major change in the way that the FreeBSD kernel handled #! at the start of an executable file passed to execve(), to bring it more into line with some other operating system kernels, including Linux and the NetBSD kernel. Commentary i...
FreeBSD shebang error
1,584,914,963,000
I have a project with some lua and some bash files. I want to loop over all files and depending on the shebang I want to execute a validity check.
You can use find and awk to check the first line (your awk has to support FNR, like POSIX awks do) and add some search patterns to find (like excluding hidden folders): echo "check bash files ..." find . -not -path '*/\.*' \ -type f -exec awk 'FNR == 1 && /^#!.*sh/{print FILENAME}' {} + | \ while IFS= read -r f; ...
validity check all files in a folder depending on the shebang [closed]