Check $BINDIR value - linux

First of all I need to apology, I have very little Unix/Linux knowledge.
I am following http://dns323.kood.org/howto:subversion to install SVN server on my DLink DNS323 device. I have successfully install Fonz Fun Plug. And I think I installed subversion-1.5.2-1.tgz as well.
According to the document I need to run svnserve.sh, in which part of the soruce code is
svnserve_start() {
if [ -x "{$BINDIR}/svnserve" ]; then
echo "Starting svnserve deamon... "
${BINDIR}/svnserve -d -r ${REPOSITORY}
else
echo "ERROR: svnserve not found or not executable"
fi
}
I got ERROR: svnserve not found or not executable message, so it looks like to me $BINDIR is not defined well.
Anybody knows, how can I do echo to display the value of $BINDIR?
Thanks!

echo $BINDIR before the if statement to check whether {$BINDIR}/svnserve exists.
It seems that {$BINDIR}/svnserve is not executable. Find that file and chmod u+x which add executable attr to it.

Related

writing a function in bash profile, calling from terminal

I'm new to linux and working in the terminal, and wrote a function to see if I'm on the company network or not
function isCompanyNetwork() {
if [[ $(ipconfig getifaddr en0) == 3.* ]] || [[ $(ipconfig getifaddr en1) == 3.* ]] ;
then
echo yes
else
echo no
fi
}
however, when i type the following in my terminal: isCompanyNetwork
I get:
-bash: isCompanyNetwork: command not found
what am I doing wrong?
Add this function to your ~/.bashrc
I'm guessing you wrote this in a file? If it's .bash_profile or .bashrc, you need to relog in or source the files (i.e. . ~/.bash_profile). If you did this at the command line and haven't logged out, you can see your defined fuctions by typing declare -F. Make sure isCompanyNetwork is there, or you did something wrong (created it in another window?).

symlink to executable doesn't launch application, error: <symlink> doesn't exist

I have a symlink to an executable, which I've created as follows:
$ ln -s /home/x/app/wps_office/wps
If on the commandline I type:
$ /home/x/app/wps_office/wps
Then my application launches correctly, but if I try to launch my application through the symlink, then I get the following error:
$ wps
wps does not exist!
Just to make sure if the symlink is correct;
$ readlink wps
/home/x/app/wps_office/wps
The folder /home/x/bin is where I've created the symlink, this folder is included in my $PATH variable.
I don't see what is going wrong here, why doesn't my application execute when I use the symlink?
Quick update;
I've just quickly looked trough the contents of the file where the symlink is pointing to, it looks like the message wps does not exist is actually coming from the application, meaning the symlink is actually correct. I don't know the exact reason why, as I find it strange that everything works correctly when I don't use the symlink. I need to look more thorougly to the code to find that out.
The code of the file where the symlink is pointing to:
#!/bin/bash
gOpt=
gTemplateExt=("wpt" "dot" "dotx")
gBinPath=$(dirname "$0")
if [ -d "${gBinPath}/office6" ]; then
gInstallPath=${gBinPath}
else
gInstallPath=/opt/kingsoft/wps-office
fi
gApp=wps
function parse_arg()
{
if [ $# -eq 1 ] ; then
ext="${1##*.}"
if [ "" = "${ext}" ] ; then
return 0
fi
for i in ${gTemplateExt}
do
if [ "${ext}" = "${i}" ] ; then
gOpt=-t
fi
done
fi
}
function run()
{
oldPwd="${PWD}"
if [ -e "${gInstallPath}/office6/${gApp}" ] ; then
if [ -d /usr/lib32/gtk-2.0 ]; then
export GTK_PATH=/usr/lib32/gtk-2.0
fi
${gInstallPath}/office6/${gApp} ${gOpt} "$#" || ${gBinPath}/wps_error_check.sh ${gInstallPath}/office6/${gApp}
else
echo "${gApp} does not exist!"
fi
}
function main()
{
parse_arg "$#"
run "$#"
}
main "$#"
Note the line where it says echo "${gApp} does not exist!", this is where my error is coming from.
Commands will only be executed without any path elements if they're part of the shell, or if they're in the PATH environment variable. Try
./wps
in the directory where the symlink is. Also confirm that the permissions are correct.
Change the line
gInstallPath=/opt/kingsoft/wps-office
in the script to
gInstallPath=/home/x/app/wps_office
The file where the symlink was pointing to, takes the current directory to launch a different file. This is the file actually being launched. The issue can be solved by simply creating a symlink to this file, which means a symlink to /home/x/app/wps_office/office6/wps
Another option is to edit the source file itself, as explained by #Pixelchemist. However as it concerns an application which I've downloaded and which I will probably update in the future, I think in this case that is not a preferred option.

How can I replace "bash: $COMMAND: command not found" message?

Any help would be appreciated.
Basically, I want to replace:
~]$ obvfake
bash: obvfake: command not found
With:
~]$ obvfake
[*] command not found
Thanks.
bash version 4 introduces a hook for handling missing commands; add the following to your .bashrc file.
command_not_found_handle () {
printf "[*] command not found\n"
return 127
}
You can write this to your .bashrc:
function error_handler {
if [ $? -eq 127 ]; then
echo "[*] command not found"
fi
}
trap 'error_handler' ERR
This will still show the bash: obvfake: command not found though. You can suppress this by doing:
obvfake 2> /dev/null
I'd simply redirect errors to /dev/null. If obvfake returns an exit code greater than 0 then it will echo your custom error message.
obvfake 2>/dev/null || echo "[*] command not found"
This might be a little be too general since it will not distinguish between error codes. So we could check for a specific exit code.
obvfake 2>/dev/null || {
if (( $? == 127 )); then
echo "[*] command not found"
fi
}
If I'd want to check a lot of error codes I'd replace the if expression with a case statement.
For the ease of use you could integrate that functionality inside your script and maybe wrap it up into a function to reuse it at various points of failure.
You pretty much want to know more about redirection in bash. :)
EDIT: I guess I misinterpreted the original question. I thought obvfake is a custom script complaining about commands being called but not found on the system.
As suggested by chepner... you can customize the default message by replacing the bash function (handles Signal 127 or command-not-found functionality) with the one designed by you and include that function in .bashrc script.
# function that handles command-not-found message.
command_not_found_handle() {
echo -e "My Friend, '$1' is a typo. Please correct it and re-enter the command."
return 127
}
You also can check this at: http://bitdiffferent.com/command-not-found/

Why am I getting an error when I use `uname` in my .bashrc?

In my .bashrc I have the following code
if [`uname` == "Linux"]; then
echo "It worked"
else
echo "It didn't work"
fi
But when I source my .bashrc I get the following results
[Linux: command not found
It didn't work
Strangly, the [ is not a typo, it is part of the error. If I comment out the if-statement, then the error goes away, so I am pretty sure that it is the source of the error. Plus, if I change the Linux to linux, then the error changes to lowercase also.
And if I echo uname I get Linux.
To source my .bashrc I have used source .bashrc and also have started a new bash session by typing bash on the command line terminal.
I didn't think it was that hard to check for the OS type, but I can't seem to figure out the correct syntax for the .bashrc.
I don't see what I am doing wrong, can anyone help?
You forgot a space after the square brackets. The first line has to look like this:
if [ `uname` == "Linux" ]; then
In your version, without the spaces, the [ and the output of uname is concatenated into one executable named [Linux, which does not exist in the PATH.
Bash in finicky about spacing. You need spaces in your conditional
if [ `uname` == "Linux" ]; then
echo "It worked"
else
echo "It didn't work"
fi

How do I create a directory in a makefile

I'm using Visual Studio 2005 nmake, and I have a test makefile like this:
sometarget:
-mkdir c:\testdir
I want to always create the directory, without having to specify 'sometarget'. For example, I can do this:
!if [if not exist c:\testdir\$(null) mkdir c:\testdir]
!endif
But that requires two lines, where I really only want to do the "-mkdir c:\testdir". If I just replace it with "-mkdir c:\testdir" I get an error from nmake - "fatal error U1034: syntax error : separator missing".
How can I always execute the mkdir, without messing about with !if [] stuff?
I think this will work:
-# if NOT EXIST "dir" mkdir "dir"
Make always wants to do things based on targets. It's not a general scripting tool. It looks at the targets and checks to see if they exist. If the target does not exist it executes the commands for that target.
The usual way to do this is to have a dummy target that is never going to be generated by the make scripts, so every time make runs it has to execute the relevant commands.
Or, you could add the command to a batch file that then calls your make file.
I'm not sure if there is an equivalent in Windows with nmake, but I managed to create a directory without using targets on Linux. I used the make function "shell". For example:
# Find where we are
TOPDIR := $(shell pwd)
# Define destination directory
ROOTFS := $(TOPDIR)/rootfs
# Make sure destination directory exists before invoking any tags
$(shell [ -d "$(ROOTFS)" ] || mkdir -p $(ROOTFS))
all:
#if [ -d "$(ROOTFS)" ]; then echo "Cool!"; else echo "Darn!"; fi
I hope Windows has the equivalent.
$(DIRNAME):
#[ -d $# ] || mkdir -p $#
Try using this:
-mkdir -p c:\testdir

Resources