Shebang line limit in bash and linux kernel

前端 未结 3 494
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 09:32

I\'m trying to execute python scripts automatically generated by zc.buildout so I don\'t have control over them. My problem is that the shebang line (#!) is too long for ei

3条回答
  •  猫巷女王i
    2020-11-30 10:19

    If you don't want to recompile your kernel to get longer shebang lines, you could write a wrapper:

    #!/bin/bash
    
    if [[ $# -eq 0 ]]; then
        echo "usage: ${0##*/} script [args ...]"
        exit
    fi
    
    # we're going to expand a variable *unquoted* to use word splitting, but
    # we don't want to have path expansion effects, so turn that off
    set -f
    
    shebang=$(head -1 "$1")
    if [[ $shebang == '#!'* ]]; then
        interp=( ${shebang#\#!} )        # use an array in case a argument is there too
    else
        interp=( /bin/sh )
    fi
    
    # now run it
    exec "${interp[@]}" "$@"
    

    and then run the script like: wrapper.sh script.sh

提交回复
热议问题