No such file or directory error in linux - linux

Recently I have installed a program called "paradigm". In the program path (/home/hora/Paradigm/) there is a directory "testdata" (/home/hora/Paradigm/testdata) which includes a shell script that runs an example test of the application.The first time I installed the program I was able to run the shell script(runtests.sh) but now that I try to run it I get the error of " No such file or directory", although the files which is mentioned by the error are there. I am sure the problem is due to lack of my knowledge to linux and your help will be appreciated. To show the situation:
hora#serv:~/Paradigm/testdata$ ./runtests.sh
Testing node splitting [1/2], should take seconds
diff: needs_split_1.out: No such file or directory
./runtests.sh: line 6: ../pathwaytab2daifg: No such file or directory
But if I list the content of directory the mentioned files are there:
hora#serv:~/Paradigm/testdata$ ls
complex_family_pathway.tab needs_split_1.cfg needs_split_2.out runtests.sh small_disconnected_pathway.tab
complex_family_pathway.tab.out needs_split_1.out needs_split_2.pathway.tab
And then:
hora#serv:~/Paradigm$ ls
common.h configuration.o
evidencesource.o helperScripts makefile
pathwaytab2daifg.cpp pathwaytab.h test1 configuration.cpp
evidencesource.cpp externVars.cpp main.cpp paradigm
pathwaytab2daifg.o pathwaytab.o testdata configuration.h
evidencesource.h externVars.o main.o pathwaytab2daifg
pathwaytab.cpp README.mediawiki
This is the script content(the problematic part):
#!/bin/bash
set -o pipefail
cd
echo Testing node splitting [1/2], should take seconds
../pathwaytab2daifg needs_split_1.pathway.tab needs_split_1.cfg \
| diff needs_split_1.out - || exit 1

I believe the authors of this script want you to set HOME to ~/Paradigm, or they expect you to install directly in your HOME directory (~) rather than in ~/Paradigm. Either way, this is an error on their part. A simple fix may be to move the installation to ~, or try:
env HOME=$(pwd) ./runtests.sh
(Note that the env is not necessary unless you are running a csh family shell such as csh or tcsh). Setting HOME changes the behavior of cd when called with no arguments and makes the value of HOME the target directory.

This line:
#!/bin/bash
set -o pipefail
cd #<----- here!
echo Testing node splitting [1/2], should take seconds
../pathwaytab2daifg needs_split_1.pathway.tab needs_split_1.cfg \
| diff needs_split_1.out - || exit 1
is changing the directory to ~/, which is the default argument of cd if you don't pass a path to it (see here).
You could fix the script to work from anywhere if you like, by giving cd an absolute path i.e. changing that cd line to cd /home/hora/Paradigm/testdata.

I know this is a VERY old question BUT I think my answer is relevant for others that did not find their answer.
I've been using Linux on a home server since about 2000. Recently, I've upgraded a home server to 64-bit architecture (DELL R510 w/ 2 # Xeon).
I've been using a program (text2pdf.c) since my 32-bit kernel 2.4.32 days. I had forgotten to clean and re-make the executable file before installing it on the 64-bit system. Hence, I received the same error BUT not for the reasons stated in all the answers I've found online. 'which' and 'type' gave no clues BUT using 'file' gave me the info on the libraries that were linked at compile time and they were 2.4.32 libraries. Obviously, OLD 32-bit libraries on a 4.x 64-bit kernel didn't fly. Make clean, make (and make install) cleared the problem.
Peace and blessings,
JQ

Related

How do I redirect from a built-in bin to execute an AppImage instead?

Scenario: the current version of Kate in Ubuntu 18LTS points at their customized version (which doesn't appear to support regex search capability). The bin is: /usr/bin/kate.
Desired solution: run the Kate AppImage (which has the regex search/replace functionality). The AppImage currently resides in ~/Downloads.
Question: how do I redirect the system to execute the AppImage version of Kate, instead of the built-in version?
Can I simply create a link to the AppImage in /usr/bin?
Yes, it appears you can... i.e. in my case I replaced the existing kate bin with a link that points to the appimage:
# 1st remove the existing kate binary
# (cp kate somewhere first if you want to keep a copy)
sudo rm /usr/bin/kate
# 2nd create a link in the system bin that points to the appimage
sudo link [directory where the appimage resides]/Kate.AppImage /usr/bin/kate
Done! The system will now execute the appimage when 'kate' is executed (e.g. via context menus).
=========================
UPDATE...
The above solution kinda works... it does run the appimage, however the parameters normally passed to kate (i.e. file to open) are lost in the hard link.
So... the better solution is to create a simple executable shell script (named 'kate' in the /usr/bin directory) to execute the appimage:
#!/bin/sh
exec [directory where the appimage resides]/Kate.AppImage "$#"
This passes any provided parms to the appimage.
You may want to keep (for whatever reasons) your system-installed Kate in /usr/bin/kate...
Then do not touch it. Instead create a directory in your $HOME named bin (it may already be present depending on the Linux distro you run).
Inside that directory, create a symlink:
ln -sf ~/Downloads/kate.AppImage ~/bin/kate
This may already work. If not, you have to move the ~/bin directory to the front of your path:
export PATH=${HOME}/bin:${PATH} # if you use Bash
To permanently modify this $PATH, add this same line into ${HOME}/.bashrc

How to understand this SWI-Prolog makefile - how Linux executable is created?

I am trying to compile grammar parser https://github.com/RichardMoot/Grail into Linux program according to instructions https://github.com/RichardMoot/Grail/blob/master/README and http://www.labri.fr/perso/moot/tutorial/install.html. There is manual how to create Linux executable from SWI-Prolog code http://www.swi-prolog.org/FAQ/UnixExe.html. All that is fine. But I can not find in the Makefile https://github.com/RichardMoot/Grail/blob/master/Makefile any compilation command. SWI-Prolo uses swipl command for compilation but this Makefile swipl calls only once - for displaying the version of the swipl.
I experience some hardship in installation and compilation, that is fine, I can execute/debug Makefile line by line and arrive at the result. But there is problem in my case - I can not see the ultimate goal in my makefile: which lines are responsible for the production of object files (if necessary) and which lines are responsible for the creation of the final Linux executable.
This is windowed program. The source code and documentation contains warnings about incompatibility with the SWI-Prolog 7, but that is fine, I can resolvem them myself, but as I said - I can not see the Makefile lines for creation of exe.
The source code is created by eminent scientist and I certainly don't want to disturb him by so low-level technical question. I would be happy if he continues work on theory and doesn't waste time on low level programming questions. Hope, that there are SWI-Prolog experts.
I am using latest (7.x) SWI-Prolog on Ubuntu 16.x and I have already installed all the mentioned prerequisites.
If you look closely at the provided Makefile, you'll find that the rules all and install are defined as follows (comments added by me):
all:
-cd source ; $(edit) g3 > g3.tmp # Replaces placeholders for your
# ... GRAIL_ROOT install directory.
-cd source ; mv -f g3.tmp g3 # Overwrites `g3` with the filled file.
cd source ; chmod a+x g3 # Makes it executable.
install: # Essentially copies all files to
-mkdir $(datarootdir) # ... your install directory.
-mkdir $(datadir)
cp -f $(images) $(datadir)
-mkdir $(bindir)
cp -f source/insertdot $(bindir)
chmod a+x $(bindir)/insertdot
cp -f $(resources) $(datadir)
cp -f source/*.pl $(bindir)
cp -f source/g3 $(bindir)
If you then do the common make && make install you'll end up with two folders installed in your Grail directory: bin and share. Inside the binary directory you'll have the g3 file that, regardless of being a SWI-Prolog source, has this initial line:
#!/usr/bin/swipl -q -g start -f
% [... prolog code.]
This header should allow your console terminal to determine what interpreter to use for this script (in this case, swipl). In my case, executing Grail with ./g3 returned a SWI-Prolog message indicating that wrong options/command arguments were used.
According to the man, Unix systems have to use option -s at the end of the header (but this didn't work either in my case):
From the manual:
-s file
Load file as a script. This option may be used from the shell to
make Prolog load a file before entering the toplevel.
It is also used to turn a file into an executable Prolog script
on Unix systems using the following first line
#!/usr/bin/swipl option ... -s
If you want to run this program, simply call the same command from your terminal:
swipl -q -g start -s g3

softlink to binary always use home folder path (instead of current folder)

kdevelop provides this AppImage binary:
wget -O KDevelop.AppImage https://download.kde.org/stable/kdevelop/5.1.1/bin/linux/KDevelop-5.1.1-x86_64.AppImage
chmod +x KDevelop.AppImage
./KDevelop.AppImage
It works well. So I want to make a soft link called kd to that binary in /usr/bin, eg:
/usr/bin/sudo ln -s KDevelop-5.1.1-x86_64.AppImage kd
Now if I run kd file1, I'd expect that it would open a file name file1 in the current folder, but it always tries to open a file name file1 in my home folder - which is not where it should be.
Is there some way to fix this issue?
Some possible causes:
The application always assumes that you want to open files in your home directory, effectively or literally prepending $HOME to the path. This would be a bug in any *nix program, and should be reported.
The application behaves differently when $(basename "$0") is not KDevelop.AppImage (what #Scheff said).
You are actually running a different kd.
Possible workarounds/investigations:
Pass the full path to the file on the command line. If it tries to open /home/you//full/path/you/provided it is obviously buggy, and you have a test case. If it does not, then there might be some gotcha to what your $PWD actually is. Try checking its value before running.
Symlink with the same name, using sudo ln -s KDevelop-5.1.1-x86_64.AppImage /usr/bin, and try running that. If it behaves the same, you've at least proven that the symlink is not the problem.
Run type -a kd and verify that your /usr/bin/kd comes up first. If not there might be an alias or shell built-in which takes precedence.
That said, what is the actual error message?

Temporary alias a cmd to squash an existing command, then expire upon script exit

Suppose the command bam is on my system. Let's refer to it as bam1.
Suppose that that I have another version of the bam binary on my system (bam2, although it may be named something much different).
When I run some-script, I want in that script (and all child processes) for all calls to bam to to use bam2. They will otherwise use bam1, as bam1 is in the $PATH by default for that environment.
Assume that I have the full path to bam2 available.
Assume that bam may run child processes that also call bam
Assume that if anything goes wrong, bam must revert back to bam1.
Assume unix-ish systems for now, but Windows support welcome.
$ alias bam="bam2" && bam # <== doesn't quite work. see ls test below
$ alias bam="ls" && ls # <== "-bash: bam: command not found"
I need to override an application binary pointer with another one temporarily. The usage intent is for a nodejs application, so something I can do in there that would perform better x-platform in a node context would be great.
I considered making a tmp symlink and prepending its folder to the system PATH, but I have a feeling there may be a simpler way.
Any tips?
You can create a temporary directory
tmpdir=`mktemp -d`
mark it for removal on exit
trap 'rm -rf "$tmpdir"' exit
add it to your PATH:
PATH="$tmpdir:$PATH" #<= This is the key part
and then place a link named after your override inside of $tmpdir
ln -s "$(which bam2)" "$tmpdir"/bam
Any processes you spawn from here will inherit the PATH variable (it's an environment (=exported) variable) and if they attempt to search for an executable, your temporary directory is what they'll search first.
If you're concerned about security, you'll want to make it (a possibly permanent) read-only directory instead of a temporary, writable one.

Assign directory to variable in a source file

I am building a source file with some alias to executable files (these are working just fine) and assigning directories to variables in order to get to the directory quicker, with less typing. For example, if I source example.source:
#!/usr/bin/bash
mydir="/path/to/some/dir"
I can get to /path/to/some/dir with
cd $mydir
However, I am not being able to use tab complete to navigate through other sub-directories like I would do by typing the complete path. I mean, if I use the tab key to complete the variable I get cd $mydir but not cd $mydir/ (I have to delete the last space character and manually type the slash / to see the next sub-directories). Hope this is an understandable question. Is there any workaround for this?
EDIT: the linux distribution I'm using is Slackware Linux 3.2.31.c x86_64 GenuineIntel GNU/Linux
EDIT2: GNU bash, version 4.2.37(2)-release
Apparently this feature is starting to be implemented in bash 4.3, release 26-Feb-2014 09:25.
Reading the NEWS file in bash 4.3 I found this:
i. The word completion code checks whether or not a filename
containing a
shell variable expands to a directory name and appends `/' to the word
as appropriate. The same code expands shell variables in command names
when performing command completion.
Unfortunately I cannot do a de novo installation of bash (because I'm working on a server) but I hope this can help others.
If I understand your question, then I believe it can be solved by putting this at the top of your example.source. This will list your contents every-time that you cd.
#!/usr/bin/bash
# Make cd change directories and then list the contents
function cd() {
builtin cd $*;
ls;
}
mydir="/path/to/some/dir"
cd $mydir
My other suggestion is to try to put cd within your alias. Something like this:
mydir="cd /path/to/some/dir"
$mydir

Resources