Path variable not being set with new values - unix

I have the following at the end of my script:
export PATH=/usr/openwin/bin:/opt/plat/AUTOSYS/4.0/autosys/bin:/usr/kerberos/bin::/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/netezzaClient/bin:/xenv/ant/X/1.8.0/bin:/export/opt/jdk/1.6.0_16/bin:$PATH
export JAVA_HOME=/export/opt/jdk/1.6.0_16
echo "END PATH - $PATH"
which prints this.
END PATH - /usr/openwin/bin:/opt/plat/AUTOSYS/4.0/autosys/bin:/usr/kerberos/bin::/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/netezzaClient/bin:/xenv/ant/X/1.8.0/bin:/export/opt/jdk/1.6.0_16/bin:/opt/edtsesn/share/bin:/xenv/cvs/sun4/5.6p4/1.10/bin:/xenv/rationalrose/sun4/5.x/6.0.9242/rose/bin:/opt/netscape/4.70_B2/bin:/opt/SCssh/3.4_C0/bin:/opt/PDolvwm/bin:/usr/kerberos/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/ucb:/usr/bin:/usr/local/etc:/bin:/usr/local/bin:/etc:/software/scripts:/usr/5bin:/usr/demo:/usr/openwin/bin:/usr/tran/sparc/lib:/usr/ccs/bin:/opt/sybase/1192/bin:/tmp/wm40824:/opt/edtsdba/bin:/xenv/scripts/bin:/xenv/workshop/sun4/5.8mu4/6.1a/bin:/home/pj03962/1192/bin:/home/pj03962/1192/bin:/xenv/java/X/1.6.0_11/bin:/xenv/cvs/:/xenv/java/X/1.6.0_11/bin:/xenv/cvs/sun4/5.6p4/1.10/bin:/xenv/ant/sun4/5.x/1.6.2/bin:/opt/SCssh/3.7.1_C0/bin:/opt/xemacs/bin:/home/pj03962/125/OCS-12_5/bin:/home/pj03962/125/125/bin:/opt/perforce/bin:/opt/netezzaClient/bin:/opt/netezzaClient/bin
yet
bash-3.00$ env $PATH
env: /usr/kerberos/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin: No such file or directory
No such file comes because a /home/usr/ folder does not exist for my account. But this still does not shed any light as to why it has not added the other values to the path variable.

I guess you've called your script without sourcing it.
For example, if your script is named "myscript.sh", you may have called "./myscript.sh" or "bash myscript.sh". Your modifications of env var inside the script won't leak out the script, you need to source it (call it with 'source' or '.' first).
eg:
. ./myscript.sh
The changes in myscript.sh will modify your current environment.
For the "env $PATH" : I think it's an error, since you're trying to run the command in the "PATH" variable. Which doesn't exist (/usr/kerberos/bin:/bin:... isn't the name of an existing file on your system !).
You should use instead: echo $PATH

Related

Why does `getResourceAsStream` sometimes load a resource even when there is a typo in the resource path?

I have a Jar (we'll call it a.jar) with a resource in it at path foo/bar.txt and a function as follows:
object FooBarLoader {
fun loadFooBarText() = javaClass.getResourceAsStream("foo//bar.txt")
?.bufferedReader()
?.readLines()
?.joinToString("\n")
}
When I test the function in a unit test (JUnit 4, running with Gradle 6), it loads the text from the resource file despite the obvious typo (the // in the middle of the resource path).
I also have a CLI application (in b.jar) that has a dependency on a.jar. When the CLI application calls loadFooBarText(), it got a null result due to the resource not being found. This was fixed by fixing the typo (// -> /) in the function in a.jar. No other changes were needed to fix it.
So, my question is why did the wrong path work in one situation (unit tests of a.jar) and not the other (call from b.jar)?
How do you run the unit test with a.jar ? Just run it in your IDE or use command java -jar a.jar ?
If you ran it just in IDE,I think difference is the search path between local files and zip files .
Your first application searches the file in your target directory and the second application searches it in the jar which is a compressed file.
When searching files in local path, command will be changed to right one by system.
The two commands below are the same in both Windows/Linux.
cd work//abc/ddd
cd work/abc/ddd
But when searching files in a jar file which is actually compressed zip file, path should be a restrict written or else the program will find nothing.

Symfony 5 and webpack encore in prod env : avoid hash string in build filename

When I run the command yarn build, some files are created in the public/build directory, generated files get a new filename containing a random hash string :
For only files themes/light and theme/dark I need to remove automatically the random hash string when I run the yarn build, I want to keep the original filename. I mean, currently the command generate theses files :
public/build/themes/light.3ac94fb2.css
public/build/themes/dark.064ff2f6.css
And instead, I want to have :
public/build/themes/light.css
public/build/themes/dark.css
Is it possible to do that automatically ?
If you don't mind having the files twice, one with the hash, one without, then the copyFiles plugin is probably the way to go:
This work adding, in your Encore configuration in webpack.config.js something like:
Encore
// Your usual config comes here
.copyFiles([
{
from: './assets/themes/light.css',
// or wherever the file lives in the assets folder
to: 'public/build/themes/light.css'
},{
from: './assets/themes/dark.css',
// or wherever the file lives in the assets folder
to: 'public/build/themes/dark.css'
}
])
;
Notice: untested – find more explanation here: https://symfonycasts.com/screencast/webpack-encore/copy-files
There is also a configureFilenames function, but I am not sure you'll be able to fit conditionals in it.

Unable to use environment variables in Lua code

I have some Lua code, which I use in my openresty nginx.conf file. This Lua code contains such lines:
...
local secret = os.getenv("PATH")
assert(secret ~= nil, "Environment variable PATH not set")
...
Just for testing reasons I tried to check if PATH variable is set and for some reason the assert statement does not pass. I see in the console:
Environment variable PATH not set
However, when I run this
$ echo $PATH
I see, that this variable indeed has some value. So, what is wrong with that and how can I fix it?
You need to tell nginx to make environment variables available. From the docs for the env directive: "By default, nginx removes all environment variables inherited from its parent process except the TZ variable. This directive allows preserving some of the inherited variables, changing their values, or creating new environment variables."
So, in your case you'd need to specify env PATH; in nginx.conf.

How do i locate wordpress plugin directory?

I am trying to add a function from plugin 1(wp job manager) to plugin 2(woocommerce).
I have decided to do this by including the php file from plugin 1, however I am unable to locate the file directory. I have used:
include( plugin_dir_path( __FILE__ ) . 'wp-job-manager/includes/class-wp-job-manager-applications.php');
but it returns the following error:
Warning:
include(/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/themes/listify-child/wp-job-manager/includes/class-wp-job-manager-applications.php): failed to open stream: No such file or directory in
/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/themes/listify-child/functions.php
on line 77
Please advise me as I've been stuck on this issue for really long... Thanks!!!
Wordpress setups have a constant ABSPATH defined (look at the bottom lines of wp_config.php) which points to the full and absolute path of the Wordpress setup, so in your case echo ABSPATH; would return /home/content/p3pnexwpnas05_data02/78/2394078/html/.
For most installations, appending wp-content/plugins/ to that string would point you to your plugins directory.
However, in a Wordpress configuration one can also customize the wp-content and or plugins directory to their own preference, so building plugins on ABSPATH.'wp-content/plugins/ is not recommended. Unfortunately Wordpress simply doesn't have a get_absolute_pluginspath() function or something available. A trick would be to fetch the plugins-URL, and remove the site-URL from it, so the remaining data is wp-content/plugins/ (or whatever the user has made of it). In code:
$plugins_directory = ABSPATH.str_replace(site_url()."/","",plugins_url())."/";
Which in your case would return:
/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/plugins/
You probably mean:
plugin_dir_path(__FILE__)
That gives you the directory path to the file that statement is in. So what that returns depends on where you run it. If you use this statement
include( plugin_dir_path(__FILE__) . 'wp-job-manager/includes/class-wp-job-manager-applications.php');
in the main plugin file for wp_job_manager (probably wp_job_manager.php), then plugin_dir_path(__FILE__) give the path of the directory that file is in (the plugin directory).
If you use it in some other file, you will need to adjust the rest of the path string accordingly.

Using KeyczarTool to create new keyset

Following the documentation noted in the wiki, I'm trying to use the KeyczarTool to generate new keyset. Anyone else come across this FileNotFoundException? The KeyczarTool.jar has rwx permissions and tried running via sudo.
From docs
Command Usage:
create --location=/path/to/keys --purpose=(crypt|sign) [--name="A name"] [--asymmetric=(dsa|rsa|ec)]
Creates a new, empty key set in the given location.
This key set must have a purpose of either "crypt" or "sign"
and may optionally be given a name. The optional version
flag will generate a public key set of the given algorithm.
The "dsa" and "ec" asymmetric values are valid only for sets
with "sign" purpose.
Cmd:
$ java -jar KeyczarTool-0.71f-060112.jar create --location=/keys --purpose=crypt -name="first key" --asymmetric=rsa
output:
org.keyczar.exceptions.KeyczarException: Unable to write to: /keys/meta
at org.keyczar.KeyczarTool.create(KeyczarTool.java:366)
at org.keyczar.KeyczarTool.main(KeyczarTool.java:123)
Caused by: java.io.FileNotFoundException: /keys/meta (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:145)
at org.keyczar.KeyczarTool.create(KeyczarTool.java:362)
... 1 more
With the current version of java keyczar the directory "keys" needs to be created first before running the program.
This is a known issue KeyczarTool should create directories automatically.
As #jbtule kindly pointed out you must create the keys dir first. But also include . before the slash.
Correct working command is:
$ java -jar KeyczarTool-0.71f-060112.jar create --location=./keys --purpose=crypt -name="first key" --asymmetric=rsa

Resources