Create an alias with relative path - alias

I have several directories containing abc/setup.csh. I don't want to type source abc/setup.csh every often. I tried making an alias but they did not work
alias sose='abc/setup.csh'
or
alias sose='$PWD/abc/setup.csh'
or
alias sose='./abc/setup.csh'
I got the following error:
readlink: missing operand
Try `readlink --help' for more information.
dirname: missing operand
Try `dirname --help' for more information.
I cannot use the absolute path as there are several such directories with the same hierarchy. My shell is csh. Please help.
Edit: Following is the content of my reduced setup.csh
#!/bin/csh
set called=($_)
if ( "$called" != "" ) then
set script_fn=`readlink -f $called[2]`
else
set script_fn=`readlink -f $0`
endif
set rootdir=`dirname $script_fn`
setenv ABCD $rootdir/..
setenv SCRIPTS $rootdir
set -f path=("$ABCD/kkk/bin" $path:q)
set -f path=("$SCRIPTS/precheckin_regression" $path:q)
set -f path=("$SCRIPTS/scripts" $path:q)
set -f path=("$SCRIPTS/script_gen" $path:q)
-Thanks

Related

Alias not running on sunos server

I am trying to create alias in sunos server but no luck i am putting my code of ~/.bashrc file !! (its code of my bashrc file )
alias le=`cd /Products/Logs`
If [ -f /etc/bashrc ]; then
./etc/bashrc
fi
Seems like you set wrong quotation marks. The first line must be:
alias le='cd /Products/Logs'
(with single quotes)
And this line:
./etc/bashrc
should be
. /etc/bashrc
And do not forget to logout then login. Or exec . ~/.barshrc

bash sqlplus command not found

I am trying to install sqlplus on my mac following the tutorial here: https://tomeuwork.wordpress.com/2014/05/12/how-to-install-oracle-sqlplus-and-oracle-client-in-mac-os/comment-page-1/#comment-6
I have downloaded the two packages (basic and sqlplus) and created all the directories as it says, I moved the necessary files inside the directories.
I created and copied the tnsnames.ora file with the contents:
MYDB=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCP)
(HOST=*********)
(PORT=1521)
)
(CONNECT_DATA=
(SERVER=dedicated)
(SID=MYDB-SID)
) )
And i created the .bash_profile as it says in the tutorial.
But what im stuck on is making the sqlplus run.
typing in sqlplus returns command not found.
in the tutorial it says i should use $ sqlplus username/password#database
where do i get the username and database name from?, I haven't created one yet.
Thanks in advance.
According to your article, you should do the following:
$ vi ~/.bash_profile
Add the following line to the end of the file.
alias sqlplus=’rlwrap sqlplus’
Now reload the .bash_profile:
$ source ~/.bash_profile
Looks like you missed these steps.
You can try to execute:
$rlwrap sqlplus
According to the comments below you do not have sqlplus in the $PATH.
The value of $PATH looks wrong to me: duplicates, quotes.
Option 1
Execute:
export PATH=/Applications/‌​or‌​acle/product/instantclient_64/11.2.0.4.0/bin:/usr/local/bin:/usr/bin:/bin:/us‌​r/s‌​bin:/sbin
Then execute in the same console:
$ sqlplus (or $ rlwrap sqlplus)
It will set value only for the current shell. The main idea is to have full path to the sqlplus binary in the $PATH.
Option 2
Modify ~/.bash_profile.
To save as a permanent environment variable edit ~/.bash_profile. There are some details about setting PATH in the source article.
Top down troubleshooting approach
Look for binary - use type
[bbrandt] ~/ $ type sqlplus
sqlplus is aliased to `rlwrap sqlplus'
Where is my binary.. hidden behind an alias, let's unalias
[bbrandt] ~/ $ unalias sqlplus
[bbrandt] ~/ $ type sqlplus
sqlplus is /u01/app/oracle/product/11.2.0/xe/bin/sqlplus
Found it! What happens if I modify my binary search-path?
[bbrandt] ~/ $ echo $PATH
/u01/app/oracle/product/11.2.0/xe/bin:/home/bbrandt/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
[bbrandt] ~/ $ export PATH=/home/bbrandt/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
Now, where is my binary?
[bbrandt] ~/ $ type sqlplus
bash: type: sqlplus: not found
[bbrandt] ~/ $
This is where you are... look in your $PATH variable

Shell redirection operation >|?

What is the difference between these two redirections?
[localhost ~]$ echo "something" > a_file.txt
[localhost ~]$ echo "something" >| a_file.txt
I can't seem to find any documentation about >| in the help.
>| overrides the noclobber option in the shell (set with $ set -o noclobber, indicates that files can not be written over).
Basically, with noclobber, you get an error if you try to overwrite an existing file using >:
$ ./program > existing_file.txt
bash: existing_file.txt: cannot overwrite existing file
$
Using >| will override that error and force the file to be written over:
$ ./program >| existing_file.txt
$
It's analogous to using the -f or --force option on many shell commands.
From the Bash Reference Manual Section "3.6.2 Redirecting Output":
If the redirection operator is >, and the noclobber option to the set builtin has been enabled, the redirection will fail if the file whose name results from the expansion of word exists and is a regular file. If the redirection operator is >|, or the redirection operator is > and the noclobber option is not enabled, the redirection is attempted even if the file named by word exists.
Searching for "bash noclobber" generally brings up articles that mention this somewhere. See this question on SuperUser, this section in O'Reilly's "Unix Power Tools", and this Wikipedia article on Clobbering for examples.

SQLCMD error in Batch file. Invalid Filename

echo off
if "%4" == "" goto usage
cd %3
mkdir Logs
echo Logs can be found in %3\Logs
echo
goto %4
:smmdsp
echo Updating %2..xyz table on %1
sqlcmd -S %1 -E -p -e -d %2 -i "%3\xyz.SQL" > %3\Logs\xyz.SQL.log
goto done
:usage
echo.
echo Usage
echo.
echo where SqlServer = SQL Server name
echo Database = configuration database
echo InstallPath = path to the software update files
echo Feature = Feature to update
echo.
:done
This script works if i have the batch file in C drive C:\XYZ , but if there are spaces in the path or if its in program files 86 folder C:\Program Files (x86) .It Gives out a error that says
How to handle this scenario... ?? Thank you
OK, This is the answer.
In my multiple decades of experience as a professional programmer, I have learned that most bugs that are not easily solved are not difficult because the problem itself is difficult, but because of human nature we make assumptions about the elements of our code that are simply incorrect, but we cannot "see" it because of that innate assumption. To compound that error in our own behavior, once we discover the error in our thought process we tend to be too embarrassed to tell others what the source of the issue was.
At this point in my career... I have nothing left to prove, and am more concerned with saving others the pain and waste of valuable coding time.
This is one of those insidious things that is due mostly to Microsoft being presumptuous, and removing file extensions from view by default. ...grrr I left my xanax at home today.
What I have done here, by my assuming that the file name I was trying to use as a parameter to the sqlcmd call was ... -i c:\temp\myscript.sql
and I was completely wrong. The file I was trying to reference was
c:\temp\myscript.sql.txt
but Microsoft in their attempt to try to help me removed the actual extension from view in file explorer and fooled me into thinking I had the correct file name. I didn't. Once I realized that I corrected the file name, which then made my code reference correct, and everything worked perfectly.
Try with strings :
sqlcmd -S "%1" -E -p -e -d %2 -i "%3\xyz.SQL" > %3\Logs\xyz.SQL.log

May I define aliases elsewhere than into .bashrc?

We are several persons using the same login id on Linux Box.
I want to define my own aliases without interfering with anyone.
In the .bashrc, I define a alias to my bash file defining my own aliases.
alias luc=/full/path/to/my/def_alias_luc.sh
The file /full/path/to/my/def_alias_luc.sh contains
#!/bin/bash
echo ""
echo "Defining Luc's aliases"
echo ""
echo ""
echo "aliases before..."
echo ""
alias
alias vimluc="vim -u /full/path/to/my/.vimrc "
echo ""
echo "aliases after"
echo ""
alias
After executing /full/path/to/my/def_alias_luc.sh, the alias is still undefined.
What do I miss ?
Don't you want to source that file (i.e. run it within the existing bash process) rather than spawn off a new bash process (as the first line of the script would suggest you're doing) ?