2 replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
source | link

A non-interactive login shell is unusual, but possible. If you start the shell with the zeroth argument (which is normally the name of the executable) set to a string beginning with a -, it's a login shell, whether it's interactive or not.

$ ln -s /bin/bash ./-bash
$ echo 'shopt -p login_shell; echo $-' | HOME=/none PATH=.:$PATH -bash
shopt -s login_shell
hB

Your attempt bash -c date -bash didn't work because that doesn't tell the shell to be a login shell: the zeroth argument is bash, not -bash. After bash has started, it sets the variable $0 to -bash instead of the zeroth argument, but the zeroth argument is what matters.

You can run a noninteractive login shell with su -l or su -, but you need to arrange for standard input not to be a terminal while still being able to be authorized (without having to type a password, or arranging for your password to be at the start of the input). It may be easier with sudo: run sudo true to get a presence credential, then while the credential is still valid run echo 'shopt -p login_shell; echo $-' | sudo -i.

See also Difference between Login Shell and Non-Login Shell?Difference between Login Shell and Non-Login Shell?

A non-interactive login shell is unusual, but possible. If you start the shell with the zeroth argument (which is normally the name of the executable) set to a string beginning with a -, it's a login shell, whether it's interactive or not.

$ ln -s /bin/bash ./-bash
$ echo 'shopt -p login_shell; echo $-' | HOME=/none PATH=.:$PATH -bash
shopt -s login_shell
hB

Your attempt bash -c date -bash didn't work because that doesn't tell the shell to be a login shell: the zeroth argument is bash, not -bash. After bash has started, it sets the variable $0 to -bash instead of the zeroth argument, but the zeroth argument is what matters.

You can run a noninteractive login shell with su -l or su -, but you need to arrange for standard input not to be a terminal while still being able to be authorized (without having to type a password, or arranging for your password to be at the start of the input). It may be easier with sudo: run sudo true to get a presence credential, then while the credential is still valid run echo 'shopt -p login_shell; echo $-' | sudo -i.

See also Difference between Login Shell and Non-Login Shell?

A non-interactive login shell is unusual, but possible. If you start the shell with the zeroth argument (which is normally the name of the executable) set to a string beginning with a -, it's a login shell, whether it's interactive or not.

$ ln -s /bin/bash ./-bash
$ echo 'shopt -p login_shell; echo $-' | HOME=/none PATH=.:$PATH -bash
shopt -s login_shell
hB

Your attempt bash -c date -bash didn't work because that doesn't tell the shell to be a login shell: the zeroth argument is bash, not -bash. After bash has started, it sets the variable $0 to -bash instead of the zeroth argument, but the zeroth argument is what matters.

You can run a noninteractive login shell with su -l or su -, but you need to arrange for standard input not to be a terminal while still being able to be authorized (without having to type a password, or arranging for your password to be at the start of the input). It may be easier with sudo: run sudo true to get a presence credential, then while the credential is still valid run echo 'shopt -p login_shell; echo $-' | sudo -i.

See also Difference between Login Shell and Non-Login Shell?

1
source | link

A non-interactive login shell is unusual, but possible. If you start the shell with the zeroth argument (which is normally the name of the executable) set to a string beginning with a -, it's a login shell, whether it's interactive or not.

$ ln -s /bin/bash ./-bash
$ echo 'shopt -p login_shell; echo $-' | HOME=/none PATH=.:$PATH -bash
shopt -s login_shell
hB

Your attempt bash -c date -bash didn't work because that doesn't tell the shell to be a login shell: the zeroth argument is bash, not -bash. After bash has started, it sets the variable $0 to -bash instead of the zeroth argument, but the zeroth argument is what matters.

You can run a noninteractive login shell with su -l or su -, but you need to arrange for standard input not to be a terminal while still being able to be authorized (without having to type a password, or arranging for your password to be at the start of the input). It may be easier with sudo: run sudo true to get a presence credential, then while the credential is still valid run echo 'shopt -p login_shell; echo $-' | sudo -i.

See also Difference between Login Shell and Non-Login Shell?