Last active
August 23, 2020 14:50
-
-
Save tataranovich/3a8f1f4978ea5ab7784af092de8a58fa to your computer and use it in GitHub Desktop.
Grab environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
XPROC="dbus-launch" | |
XPID="" | |
TARGET="$1" | |
if [ ! -z "$TARGET" ]; then | |
# Target is specified, check is it PID or process name | |
if echo "$TARGET" | grep -Eq '^[0-9]+$'; then | |
# Target is number, use it as PID | |
XPID="$TARGET" | |
XPROC="" | |
else | |
# Target is not number, use it as process name | |
XPROC="$TARGET" | |
fi | |
fi | |
if [ -z "$XPID" ]; then | |
# Find PID for process name started by current user | |
XPID=$(pgrep -u "$(whoami)" "$XPROC" | head -n 1) | |
fi | |
if [ ! -r "/proc/$XPID/environ" ]; then | |
echo "Failed to grab environment from $XPROC($XPID)" >&2 | |
exit 1 | |
else | |
xargs -r0 -n1 echo export < "/proc/$XPID/environ" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment