ksh source file: cannot open [No such file or directory] - ksh

Could not fix my error with the current solutions given in SO. Hence this post.
Im using ksh version as below in a linux system( Linux version 2.6.32-279.el6.x86_64 (mockbuild#c6b9.bsys.dev.centos.org) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Fri Jun 22 12:19:21 UTC 2012 ).
[userid#host home]$ ksh --version
version sh (AT&T Research) 93u+ 2012-08-01
I have 2 files in the same directory. Both given chmod 777 permissions
testvar.env
testrun.ksh
Contents of testrun.ksh
#!/usr/bin/ksh
. testvar.env
echo $month
Contents of testvar.env
export month=jan
export user=abc
But when i do ksh testrun.ksh i get this error
testrun.ksh[2]: .: testvar.env: cannot open [No such file or directory]
Tried adding below line on top of testvar.env. But no luck
#!/usr/bin/ksh
Possibilities:
Is this to do with the ksh version?
Ffile permissions?
Location it looks is somewhere else?
Does it only source other ksh files?
.env extension has anything to do?
I have also tried with replacing the file with another file from the same dir. Same result. So it seems not an issue with settings file
Update
I used #shellter s comment below to use . $PWD/settings.env to fix the error, Even though I didn't get the reason for the error. I think I found the answer here can't source script in a current directory.

Related

bash claims executable file does not exist when trying to execute it, but it does exist

A most bizarre experience that I cannot explain and has me pulling my hair out. I have a binary executable file MMM and it exists, I can see it it has the x permission set, bash even autocompletes the name when I press the TAB key and file confirms its executable but this happens:
~/tmp$ ls -l
total 56
-rwxrwxr-x 1 polyphemus polyphemus 56948 Jun 25 22:43 MMM
~/tmp$ file MMM
MMM: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.2.5, stripped
~/tmp$ ./MMM
-bash: ./MMM: No such file or directory
So I copied this file from another server, and to make sure I haven't got some strange file corruption going on, not that that would explain bash's ridiculous claim the file does not exist, I copied the file to a NAS and from the NAS back to another server and repeated exactly the same experiment, only this happens:
~/tmp$ ls -l
total 56
-rwxr-xr-x 1 bernd bernd 56948 Jun 25 22:53 MMM
~/tmp$ file MMM
MMM: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.2.5, stripped
~/tmp$ ./MMM
JAVA_HOME is not set. ./MMM cannot start.
if it helps they are both Linux Mint boxes, the one where it works is a development machine with Mint 19 and the one where it's not working is a fresh install of Mint 19.1.
The install works fine, other executables run fine and I can run then in bash with ./file.
I've studied and compared the shopts and found nothing, the aliases and found nothing. This has me pulling my hair out. I hope someone has seen this before.
It might be a library that cannot be loaded (because it doesn't exist on your system), with a bad error message. Try:
ldd .MMM
this will give you the dynamic libraries that try to be loaded, and would tell you if one is missing.
Thanks to pointers that Dennis Williamson provided the problem can be characterised as follows:
It's a well known issue. In that there is a kernel limitation that means bash only receives a status code (the one for "file not found") without any descriptive data, when the kernel attempts to load a file needed to run the binary. The message is indeed frustratingly misleading and this is a broadly known and understood issue.
As noted in the question itself this is an ELF binary: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format and the interpreter required for such a binary file can be divined with readelf -a MMM | grep interpreter which produces [Requesting program interpreter: /lib/ld-linux.so.2]
It's easy to see this file is missing on my system and it turns out that to install it we need simply to install the lib6 libraries for 32 bit architecture with sudo apt install libc6:i386
After doing this the problem scenario that was confusing me now looks like the working scenario:
~/tmp$ ls -l
total 56
-rwxrwxr-x 1 polyphemus polyphemus 56948 Jun 25 22:43 MMM
~/tmp$ file MMM
MMM: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.2.5, stripped
~/tmp$ ./MMM
JAVA_HOME is not set. ./MMM cannot start.
And the binary runs just fine!
A pleasing result. With many thanks to StackOverflow and to Dennis Williamson.
well the error seems is whith JAVA_HOME env variable
JAVA_HOME is not set. ./MMM cannot start.
Just set the JAVA_HOME from whatever java version you use
you can run it inline like this
JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::") ./MMM

Does `Fish` change the order of $PATH? How to avoid that

fish --version
> fish, version 3.0.2
uname -a
> Darwin Jerrys-MacBook.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
echo $TERM
> xterm-256color
I have compare my $PATH in bash and fish shell, the order of rvm changed, which cause which pod become different(i used rvm to manage ruby).
How can I make them same order ?
By the way,
I have include all my setting in .bashrc and load it by source ~/.bashrc in .bash_profile, noting in .prfile
And I have nothing in ~/.config/fish/config.fish
The begin character of x,~,=,> just I added mark to compare easily.
----- echo $PATH
=:~/.rvm/gems/ruby-2.2.9/bin
=:~/.rvm/gems/ruby-2.2.9#global/bin
=:~/.rvm/rubies/ruby-2.2.9/bin
X=:/opt/local/bin
X=:/opt/local/sbin
=:~/.nvm/versions/node/v8.11.3/bin
~:/usr/local/bin
~:/usr/bin
~:/bin
~:/usr/sbin
~:/sbin
>:/usr/local/share/dotnet
>:/opt/X11/bin
>:/Library/Frameworks/Mono.framework/Versions/Current/Commands
X-:~/.rvm/bin
X-:~/.local/bin
X-:/usr/local/Cellar/aria2/1.33.1/bin
X-:~/Documents/code/flutter/sdk/flutter/bin
X-:~/Documents/code/flutter/sdk/flutter/bin/cache/dart-sdk/bin
X-:~/Documents/code/flutter/sdk/flutter/.pub-cache/bin
------ fish & echo $PATH
~/usr/local/bin
~/usr/bin
~/bin
~/usr/sbin
~/sbin
>/opt/X11/bin
>/usr/local/share/dotnet
>/Library/Frameworks/Mono.framework/Versions/Current/Commands
=~/.rvm/gems/ruby-2.2.9/bin
=~/.rvm/gems/ruby-2.2.9#global/bin
=~/.rvm/rubies/ruby-2.2.9/bin
X=/opt/local/bin
X=/opt/local/sbin
=~/.nvm/versions/node/v8.11.3/bin
X-~/.rvm/bin
X-~/.local/bin
X-/usr/local/Cellar/aria2/1.33.1/bin
X-~/Documents/code/flutter/sdk/flutter/bin
X-~/Documents/code/flutter/sdk/flutter/bin/cache/dart-sdk/bin
X-~/Documents/code/flutter/sdk/flutter/.pub-cache/bin
Here is a simple workaround from this PR,
# Download patched config
curl -O https://raw.githubusercontent.com/fish-shell/fish-shell/e18354bc6ef937e2e663fc098cc51a2546d4d2d0/share/config.fish
# Install config
mv config.fish /usr/local/share/fish/
here how i solved it (using fish only as interactive on top of my zsh):
in .zshrc:
export ZSHPATH="$PATH"
fish
in .config/fish/config.fish
set PATH $ZSHPATH $PATH
To be simple, download & install the version fish-2.7.1.pkg which don't have this bug on Mac.
According to code commit, next version fish-3.1.0 may fix this bug.

Installation of Clingo on a Mac

I am trying to install Clingo on my Mac (macOS Mojave -- 10.14.3).
I have downloaded the last version of Clingo (5.3.0) and unzipped it. If I open the Clingo file with the terminal it says:
Last login: Fri Mar 1 09:31:31 on ttys000
Mattias-MacBook-Pro:~ esther$
/Users/esther/Documents/clingop/clingo ; exit;
clingo version 5.3.0
Reading from stdin
I have also downloaded homebrew and Xcode.
I have .lp file (pippo.pl) that I would like to run. What should I do to run this file?
I tried in several ways from the Terminal, but nothing happens.
I have created an alias clingo="documents/clingop/clingo" and then from the directory of the pippo.pl file I wrote
clingo pippo , but the Terminal says: -bash: documents/clingop/clingo: No such file or directory
So it seams that somehow it cannot read the file clingo
Do you know how I could solve this? thanks a lot
The important line is Reading from stdin.
You can call clingo so that it processes your file as follows:
/Users/esther/Documents/clingop/clingo pippo.pl
or if your shell is bash (or similar):
cat pippo.pl |/Users/esther/Documents/clingop/clingo
or
/Users/esther/Documents/clingop/clingo <pippo.lp

How can I debug the Bourne Shell with gdb?

I built a toolchain script to prepare a Linux build environment. The script can be found here: https://github.com/mynameismevin/prometheus/blob/toolchain/ptool-make.sh
The script runs perfectly until after the Perl section around line 416. After Perl is done, when it goes to unzip sed, it complains with this error:
tar (child): sed-4.2.2.tar.bz2: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
However, if I run the sections by hand, it completes without errors. If I split the script into ptool-make1.sh (which ends at Perl) and ptool-make2.sh (which starts at sed) and run them sequentially then they both complete without any issues at all. At this point, I assert the issue isn't with the script, and I would like to debug the shell to see if it's an issue with the shell.
Here are some useful configurations:
user#ubuntu:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"
user#ubuntu:~$ bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
user#ubuntu:~$ ls -lh $(which bash)
-rwxr-xr-x 1 root root 998K Oct 7 2014 /bin/bash
I don't think Ubuntu bash comes with debugging symbols, so I would assume I would have to recompile to include those?
How would I use gdb to debug the shell when I run a script? Or how would I have the shell log to a file while the script runs so I can open it with gdb after it's done? I know how to debug a shell script, I don't want to debug the script, I want to debug the shell.
Edit: It doesn't look like Ubuntu bash comes with debugging symbols out of the box. Reading symbols from bash...(no debugging symbols found)...done.
Edit: $PROMETHEUS is set in my root shell. At the end of Perl cd .. results in the same results a cd $PROMETHEUS/sources/.
Shells come with their own debugging tools. The most simple is running them with -x (bash -x ...script...) which will print each command after variable expansion but before it is executed. That's usually enough to determine the problem.
For more ideas, see How to debug a bash script?
You should also consider to write helper functions to reduce the size of the script to just a few lines. You could move special options to configure or post-build steps into extra files and run them from the helper function if they exist.
Looking at the code, it seems that this line is the culrit:
cd $PROMETHEUS/sources/
everywhere else, you just use cd ... If PROMETHEUS isn't defined (the script doesn't define it, that becomes cd /sources/ which should also fail but doesn't abort your script. Try
cd $PROMETHEUS/sources/ || exit 1
instead. Also #!/bin/bash -u might be useful (abort on undefined variables).
Lastly, you can use pushd and popd to navigate the folders.

dotfiles errors | /Users/marif/.aliases:79: bad option: -t

I am pretty new to OSX but everything is almost settled down, I had configured Z and ZSH earlier and lately come to know about paulirish dot files from https://github.com/paulirish/dotfiles and installed it.
Got to see following output when I refresh .bash_profile or .bashrc
Last login: Tue May 14 08:41:35 on console
ls
➜ ~ ls
Applications Downloads Music Samsung dotfiles log
Desktop Library Pictures Sites install-deps.sh readme.md
Documents Movies Public bin js-boilerplate
➜ ~ z
zsh: command not found: z
➜ ~ source ~/.bash_profile
/Users/marif/.aliases:79: bad option: -t
/Users/marif/.aliases:82: bad option: -t
/Users/marif/.functions:37: parse error near `]]'
/Users/marif/.bash_profile:.:9: no such file or directory: /Users/marif/code/z/z.sh
/Users/marif/.bash_profile:15: command not found: shopt
/Users/marif/.bash_profile:26: command not found: complete
\[\e]2;/Users/marif\[\a\]\[\e]1;\]Users/\W\[\a\]marif at \[\]\w\[\]\[\]\[\]\n$ \[\]
I don't know what's going wrong here, would help if somebody point me out to issue persisting in my profile or something.
zsh is not bash and when I launch "zsh", I see the same error that you do:
[/tmp]:;zsh
ElvisIsAliveAndWell-2% type -t
zsh: bad option: -t
These paulirish dot files are meant to be used with bash. Either use bash or you'll need to port the lines in the dot files that are throwing errors so that they will work in zsh (and if you do this, you can fork or branch or suggest changes to PaulIrish so he can pick up these changes and make them available for other interested folks).

Resources