etc/profile:
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi
export PATH
unset ROOTPATH
echo $PATH:
/sbin:/bin:/usr/sbin:/usr/bin
So:
/usr/local/bin is not showing up, so I think it may be using a different file.
I have tried putting export PATH=$PATH:/usr/local/bin and it's fine but that is not permanent.
Check your shell init files, for bash that would be /etc/bashrc or /etc/bash.bashrc or something like that as well as ~/.bashrc and ~/.bash_profile. Most shells have similiar init scripts, check the manual.
Also check out /etc/env.d/* and /etc/environment.
Related
This question already has answers here:
Can a shell script set environment variables of the calling shell? [duplicate]
(20 answers)
Closed last month.
I am trying to write a bash script that will take a single argument("prod" or "staging"), and use that to conditionally set global environment variables, specifically to switch between my staging and prod AWS keys. However, even though my logs in the script show what I expect, running echo $AWS_ACCESS_KEY in my terminal after running the script, does not show it was updated. I have tried adding source ~/.zshrc but I don't think that is needed. What can I change to update the $AWS_ACCESS_KEY globally?
#!/bin/bash
tmpAccess="access"
tmpSecret="secret"
if [ $1 == "prod" ];
then
echo "Setting the AWS KEYS to $1 keys"
tmpAccess=$PROD_ACCESS_KEY
tmpSecret=$PROD_SECRET_KEY
elif [ $1 == "staging" ];
then
echo "Setting the AWS KEYS to $1 keys"
tmpAccess=$STAGING_ACCESS_KEY
tmpSecret=$STAGING_SECRET_KEY
else
echo "Unknown env passed in: $1"
fi
export AWS_ACCESS_KEY=$tmpAccess
export AWS_SECRETS_KEY=$tmpSecret
echo "Updated AWS_ACCESS_KEY: $AWS_ACCESS_KEY"
echo "Current tmpAccess: $tmpAccess"
echo "AWS_ACCESS_KEY has been updated to $AWS_ACCESS_KEY for env $1"
echo "AWS_SECRETS_KEY has been updated to $AWS_SECRETS_KEY for env $1"
source ~/.zshrc
My zshrc file looks similar to:
export STAGING_ACCESS_KEY=1234
export STAGING_SECRETS_KEY=abcd
export PROD_ACCESS_KEY=5678
export PROD_SECRETS_KEY=efgh
Clearly, it's not possible to put in a script a program to modify a variable in the current terminal except if you accept to source it (see Setting environment variable in shell script does not make it visible to the shell).
There is another solution. Put your script content in a function:
myfunctionName () {
tmpAccess="access"
tmpSecret="secret"
if [ $1 == "prod" ];
then
echo "Setting the AWS KEYS to $1 keys"
tmpAccess=$PROD_ACCESS_KEY
tmpSecret=$PROD_SECRET_KEY
elif [ $1 == "staging" ];
then
echo "Setting the AWS KEYS to $1 keys"
tmpAccess=$STAGING_ACCESS_KEY
tmpSecret=$STAGING_SECRET_KEY
else
echo "Unknown env passed in: $1"
fi
export AWS_ACCESS_KEY=$tmpAccess
export AWS_SECRETS_KEY=$tmpSecret
echo "Updated AWS_ACCESS_KEY: $AWS_ACCESS_KEY"
echo "Current tmpAccess: $tmpAccess"
echo "AWS_ACCESS_KEY has been updated to $AWS_ACCESS_KEY for env $1"
echo "AWS_SECRETS_KEY has been updated to $AWS_SECRETS_KEY for env $1"
}
and put this function in your .zshrc file.
After that, launch a new terminal and call your myfunctionName function like the script filename.
I want to configure zsh to append the time each command started next to the line command was executed on. For example:
# before I press ENTER
$ ./script
# after I press enter
$ ./script [15:55:58]
Running script...
I came up with the following config (which also colors the timestamp yellow):
preexec () {
TIME=`date +"[%H:%M:%S] "`
echo -e "$1 %{$fg[yellow]%}\033[1A\033[1C${TIME}$reset_color"
}
But it breaks and prints { and % characters on basic commands such as cat and echo. It also breaks on password prompts (macOS terminal). For example with echo:
$ echo "hello" [15:55:58]
hello"hello" %{%}
How can I fix this config?
Thank you.
You inspired me and based on your script I wrote mine. I have tested this on zsh 5.4.smth.
preexec () {
local TIME=`date +"[%H:%M:%S] "`
local zero='%([BSUbfksu]|([FK]|){*})'
local PROMPTLEN=${#${(S%%)PROMPT//$~zero/}}
echo "\033[1A\033[$(($(echo -n $1 | wc -m)+$PROMPTLEN))C $fg[blue]${TIME}$reset_color"
}
In your ~/.zshrc file, put:
function preexec() {
timer=${timer:-$SECONDS}
}
function precmd() {
if [ $timer ]; then
timer_show=$(($SECONDS - $timer))
export RPROMPT="%F{cyan}${timer_show}s %F{$black%}"
unset timer
fi
}
And that should give you something like this:
I add depends packet to a exist .bb file, such as add DPENDS="AAA" line to .bb file, when I compile the .bb file, it failed for XXX rdepends on AAA-dev [dev-deps], and I search google, all the answer almost is add line INSANE_SKIP_${PN} += "dev-deps" or RDEPENDS_${PN}_remove = "AAA-dev" to .bb file.
But my question is why? why one packet depend AAA packet, it should also RDPENDS AAA-dev, is there any other answer to fix this problem
The bb source file is:
inherit autotools qcommon
DESCRIPTION = "Daemon to handle AT commands"
DEPENDS = "glib-2.0 qmi qmi-framework qmi-client-helper ocean-link"
SRC_DIR = "${WORKSPACE}/atfwd-daemon/"
S = "${WORKDIR}/atfwd-daemon/"
PR = "r3"
EXTRA_OECONF += "--with-glib --with-common-includes=${STAGING_INCDIR}"
do_configure_append() {
echo "/*This is compiled to generate, only look don't try*/" > ${S}atfwd_config.h
echo "#ifndef _ATFWD_CONFIG_H_" >> ${S}atfwd_config.h
echo "#define _ATFWD_CONFIG_H_" >> ${S}atfwd_config.h
#//<!-- ODM feature caogang#2015-07-13
if [ "${PRJ_NAU8810}" = "NAU8810_CODEC" ]; then
echo "#define NAU8810_CODEC" >> ${S}atfwd_config.h
fi
if [ "${FEATURE_ACDB_ENABLE}" = "true" ]; then
echo "#define FEATURE_ACDB_ENABLE 1" >> ${S}atfwd_config.h
fi
if [ "${PRJ_XXX}" != "" ]; then
echo "#define ${PRJ_XXX}" >> ${S}atfwd_config.h
fi
#//end-->
I add a DEPENDS on onenet pkg
inherit autotools qcommon
DESCRIPTION = "Daemon to handle AT commands"
DEPENDS = "glib-2.0 qmi qmi-framework qmi-client-helper ocean-link onenet"
SRC_DIR = "${WORKSPACE}/atfwd-daemon/"
S = "${WORKDIR}/atfwd-daemon/"
PR = "r3"
EXTRA_OECONF += "--with-glib --with-common-includes=${STAGING_INCDIR}"
do_configure_append() {
echo "/*This is compiled to generate, only look don't try*/" > ${S}atfwd_config.h
echo "#ifndef _ATFWD_CONFIG_H_" >> ${S}atfwd_config.h
echo "#define _ATFWD_CONFIG_H_" >> ${S}atfwd_config.h
#//<!-- ODM feature caogang#2015-07-13
if [ "${PRJ_NAU8810}" = "NAU8810_CODEC" ]; then
echo "#define NAU8810_CODEC" >> ${S}atfwd_config.h
fi
if [ "${FEATURE_ACDB_ENABLE}" = "true" ]; then
echo "#define FEATURE_ACDB_ENABLE 1" >> ${S}atfwd_config.h
fi
if [ "${PRJ_XXX}" != "" ]; then
echo "#define ${PRJ_XXX}" >> ${S}atfwd_config.h
fi
#//end-->
The onenet.bb is:
inherit pkgconfig cmake
DESCRIPTION = "onenet sdk"
LICENSE = "PD"
PR = "r0"
LIC_FILES_CHKSUM = "file://${WORKDIR}/git/LICENSE;md5=bae84cdd023be37582157d865da54cc6"
SRCREV = "065d98dd8de91544315d6167ce73626ce739666d"
SRC_URI = "git://github.com/cm-heclouds/MQTT.git;protocol=https"
S = "${WORKDIR}/git/mqtt_sdk"
do_install() {
install -d ${D}/usr/lib
install -d ${D}/usr/include/onenet
install -m 0644 ${B}/bin/libmqtt.so -D ${D}/usr/lib/
for inc in $(find ${S} -name *.h ! -name 'cJSON.h'); do
install -m 0644 ${inc} -D ${D}/usr/include/onenet
done
}s
The sanity check documentation explains this:
dev-deps: Checks that all packages except -dev or -staticdev packages
do not depend on -dev packages, which would be a packaging bug.
It's telling you that in your current recipe "XXX" runtime-depends on "AAA-dev" and that this is a normally an error. You need to find out how/why this dependency is added before you can decide what the correct solution is.
Based on the added recipes: The issue seems to be that onenet build produces an unversioned ".so" file. This is typically a mistake (the actual library file should be e.g. "libmqtt.so.1.1" and the unversioned file should just be a symlink to the versioned one). I'm very surprised that you are not getting a fatal error on this issue when you build onenet. Are you suppressing the QA error for this?
Since you've managed to build onenet somehow, you now probably have a onenet-dev package that erroneously contains the actual library: The build system notices this during atfwd-daemon build, adds a runtime dependency to onenet-dev (because that's where the library is) and then the QA error triggers because normal packages should not depend on -dev packages.
Possible fixes:
Either fix the onenet build system so it produces a versioned library, or
Force the .so file to be packaged into the actual onenet package instead of onenet-dev, like this:
FILES_${PN}-dev = "${includedir}/"
FILES_${PN} += "${libdir}/libmqtt.so"
A bonus suggestion: Using directory variables instead of paths like /usr/include and /usr/lib (like I did above) is a good "Best Practice".
I'm wrote a function called test_status that I am trying to incorporate in my tmux status bar. To give some background, my tests will output to a file called .guard_result with either success or failure and the test_status function reads from that file and echoes a 💚 if my tests are passing and a ❤️ if they are failing.
The good news is running test_status works just fine, I'm just having trouble getting it to work with tmux. What am I missing here?
# ~/.oh-my-zsh/custom/aliases.zsh
function test_status {
if [ ! -f "./.guard_result" ]; then
echo "?"
return 1
fi
result="$(cat ./.guard_result)"
if [[ $result == *"success"* ]]
then
echo "💚";
elif [[ $result == *"fail"* ]]
then
echo "❤️";
fi
}
This function works... Here is Tmux configuration (which doesn't show result):
# ~/.tmux.conf
set -g status-right "#(test_status) #[fg=colour245]%d %b %Y #[fg=white]:: #[fg=colour245]%l:%M %p"
I know I must be missing something simple... Thanks for your help!
tmux passes shell commands to /bin/sh not zsh. And even if tmux would use zsh, the function would not be available in that context as ~/.zshrc, which loads oh-my-zsh, is only read for interactive shells.
In order to get the the output of test_status into tmux, I would suggest to put the function into a zsh script and call that.
You can either source ~/.oh-my-zsh/custom/aliases.zsh from within the script and then call test_status:
#!/usr/bin/zsh
# ^ make sure this reflects the path to zsh (`type zsh`)
source ~/.oh-my-zsh/custom/aliases.zsh
test_status
Or you can just put the entire function into the script, so as to not clutter alias.zsh:
#!/usr/bin/zsh
function test_status {
if [ ! -f "./.guard_result" ]; then
echo "?"
return 1
fi
result="$(cat ./.guard_result)"
if [[ $result == *"success"* ]]
then
echo "💚";
elif [[ $result == *"fail"* ]]
then
echo "❤️";
fi
}
Safe the script somewhere (e.g. /path/to/test_status.zsh), make it executable (chmod a+x /path/to/test_status.zsh) and call it by path in the tmux configuration.
I am using KornShell (ksh) on Solaris and currently my PS1 env var is:
PS1="${HOSTNAME}:\${PWD} \$ "
And the prompt displays: hostname:/full/path/to/current/directory $
However, I would like it to display: hostname:directory $
In other words, how can I display just the hostname and the name of the current directory, i.e. tmp or ~ or public_html etc etc?
From reading the ksh man page you want
PS1="${HOSTNAME}:\${PWD##*/} \$ "
Tested on default ksh on SunOS 5.8
Okay, a little old and a little late, but this is what I use in Kornshell:
PS1='$(print -n "`logname`#`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")'
This makes a prompt that's equivalent to PS1="\u#\h:\w\n$ " in BASH.
For example:
qazwart#mybook:~
$ cd bin
qazwart#mybook:~/bin
$ cd /usr/local/bin
qazwart#mybook:/usr/local/bin
$
I like a two line prompt because I sometimes have very long directory names, and they can take up a lot of the command line. If you want a one line prompt, just leave off the "\n" on the last print statement:
PS1='$(print -n "`logname`#`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "$ ")'
That's equivalent to PS1="\u#\h:\w$ " in BASH:
qazwart#mybook:~$ cd bin
qazwart#mybook:~/bin$ cd /usr/local/bin
qazwart#mybook:/usr/local/bin$
It's not quite as easy as setting up a BASH prompt, but you get the idea. Simply write a script for PS1 and Kornshell will execute it.
For Solaris and other Older Versions of Kornshell
I found that the above does not work on Solaris. Instead, you'll have to do it the real hackish way...
In your .profile, make sure that ENV="$HOME/.kshrc"; export ENV
is set. This is probably setup correctly for you.
In your .kshrc file, you'll be doing two things
You'll be defining a function called _cd. This function will change to the directory specified, and then set your PS1 variable based upon your pwd.
You'll be setting up an alias cd to run the _cd function.
This is the relevant part of the .kshrc file:
function _cd {
logname=$(logname) #Or however you can set the login name
machine=$(hostname) #Or however you set your host name
$directory = $1
$pattern = $2 #For "cd foo bar"
#
# First cd to the directory
# We can use "\cd" to evoke the non-alias original version of the cd command
#
if [ "$pattern" ]
then
\cd "$directory" "$pattern"
elif [ "$directory" ]
then
\cd "$directory"
else
\cd
fi
#
# Now that we're in the directory, let's set our prompt
#
$directory=$PWD
shortname=${directory#$HOME} #Possible Subdir of $HOME
if [ "$shortName" = "" ] #This is the HOME directory
then
prompt="~$logname" # Or maybe just "~". Your choice
elif [ "$shortName" = "$directory" ] #Not a subdir of $HOME
then
prompt="$directory"
else
prompt="~$shortName"
fi
PS1="$logname#$hostname:$prompt$ " #You put it together the way you like
}
alias cd="_cd"
This will set your prompt as the equivelent BASH PS1="\u#\h:\w$ ". It isn't pretty, but it works.
ENV=~/.kshrc, and then in your .kshrc:
function _cd {
\cd "$#"
PS1=$(
print -n "$LOGNAME#$HOSTNAME:"
if [[ "${PWD#$HOME}" != "$PWD" ]]; then
print -n "~${PWD#$HOME}"
else
print -n "$PWD"
fi
print "$ "
)
}
alias cd=_cd
cd "$PWD"
Brad
HOST=`hostname`
PS1='$(print -n "[${USER}#${HOST%%.*} ";[[ "$HOME" == "$PWD" ]] && print -n "~" ||([[ "${PWD##*/}" == "" ]] && print -n "/" || print -n "${PWD##*/}");print "]$")'
PS1=`id -un`#`hostname -s`:'$PWD'$
and...
if you work between two shells for most of your effort [ksh and bourne sh]
and desire a directory tracking display on your command line
then PWD can be substituted easily in ksh
and if you use /usr/xpg4/bin/sh for your sh SHELL, it will work there as well
Try this:
PS1="\H:\W"
More information on: How to: Change / Setup bash custom prompt, I know you said ksh, but I am pretty sure it will work.