A very simple script, but alias won't work


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers A very simple script, but alias won't work
# 1  
Old 05-21-2010
A very simple script, but alias won't work

I am new to unix and therefore I did a lot of reading before posting. So please, if this has been answered before, forgive me for re-posting and point me to the right place for the answer. I have spent many hours searching the net and read over 50 posts in this forum and even tried a few thing but still no success.

Here is my simple script file named al:

#!/bin/csh
echo Setting alias....
alias ss "vi myfile.log"

I type al on the command line, it displays the message on the screen as per Echo command but doesn't seem to set the alias ss. When I type ss on the command line, I get:

ss: command not found.

I even tried ./al and then ss as read in some posts but didn't work. Also tried with '=' sign i.e. ss="vi myfile.log", still no go. If I type the command interactively then the alias works fine.

I am using c shell i.e. when I type echo $shell, I get /bin/csh.

Any help to get this working will be greatly appreciated and save me a lot of time.

Thanks.
# 2  
Old 05-21-2010
Invoke as dot-space-scriptname if you want anything set in the script to stay in the current environment.

Code:
. ./scriptname

# 3  
Old 05-21-2010
Tried that. I get the message "Permission Denied".

. ./al [Enter]
/idn/app/bin/.: Permission Denied.

I don't know what that means.
# 4  
Old 05-21-2010
let try this
Code:
chmod u+x al

So must give execute permission to your script
# 5  
Old 05-21-2010
Quote:
Originally Posted by ygemici
let try this
Code:
chmod u+x al

So must give execute permission to your script
Tried that. Still no go. Same message.
# 6  
Old 05-21-2010
Permissions typically cascade along the path, so be sure that your UID has access to execute along the entire path to your script.

Otherwise, if your script is exclusively to set the named alias...just add this to your . file and have it set on login.

csh...bad! Smilie

Code:
ls -ld .


Last edited by curleb; 05-21-2010 at 01:11 PM..
# 7  
Old 05-21-2010
Quote:
Originally Posted by curleb
Permissions typically cascade along the path, so be sure that your UID has access to execute along the entire path to your script.

Otherwise, if your script is exclusively to set the named alias...just add this to your . file and have it set on login.

csh...bad! Smilie

Code:
ls -ld .

I don't have problem executing other scripts. Only the alias command is not working.

Setting it on login kinda defeats the purpose. This is a script that I want to run on the fly passing a parameter to the script and might run it several times during a session with different parameters. For example, I would like to eventually modify the alias command to some thing like this:

alias ss "vi $1.log"
alias tt "vi $1.txt"
alias kk "vi $1.ksh"

and run the script just by typing al myfile to set the 3 aliases as above pointing to myfile.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script won't run because hardware won't produce display

Can anyone offer any advice on how to modify the script below to work on a new system we have, that has no graphics capability? We admin the system through a serial RAS device. I've tried running the below script through the RAS and through an ssh -X session. It failed with something like "GTK... (3 Replies)
Discussion started by: yelirt5
3 Replies

2. Shell Programming and Scripting

Nested double quotes won't work in my bash script?

In a bash script I have: LSCMD="find /project/media/ -mindepth 2 -maxdepth 2 -name \"files*pkg\"" ALL_PACKAGES=$( $LSCMD | sort 2>/dev/null) But I get nothing returned. It's just all blank. If I run the find command in a terminal, I get dozens of hits. I figure it's the way how I'm... (3 Replies)
Discussion started by: superbbrr
3 Replies

3. BSD

Install cd won't work

Hi! I'm sure that somebody here installed freeBSD from a download of a virtual disc (.iso). But I made 5 downloads of 5 differents freeBSD installation (and no one has worked).Can somebody tell me where to download and how (if needed) to prepare the cd? (8 Replies)
Discussion started by: maxum
8 Replies

4. Shell Programming and Scripting

Crontab - wrote Simple Script but i cant work out how to play it at a certain time.

Hi everyone. Silly might be silly be I'm still new to bash. I'm trying to make an Alarm Clock for in the morning using my laptop i have wrote this Simple Script but i cant work out how to play it at a certain time. #!/bin/bash cd /home/josh/Music/Bruno_Mars/Hooligans/ cvlc... (8 Replies)
Discussion started by: jtsmith90
8 Replies

5. Shell Programming and Scripting

created a .alias, but they won't take (ksh)

I login with a common username, and have no access to the different login scripts for my personalizations. So for a while, I would hobble on over to a directory I made for myself, and then bring in my alias file where I would fix my backspace, create a few aliases, etc.: $ ./.alias $ Now... (4 Replies)
Discussion started by: hindesite
4 Replies

6. UNIX for Dummies Questions & Answers

sed won't work

Hi All, can anybody tell me what's wrong with this code? # SEARCH replaced by REPLACE #!/bin/bash SEARCH="95$$ 0 t" REPLACE="95$$ 1 t" for I in `ls *000.inp | cut -c-12`; do echo $I sed 's/$SEARCH/$REPLACE/' ${I}-000.inp > ${I}-100.inp done It don't replace the string... (5 Replies)
Discussion started by: f_o_555
5 Replies

7. Shell Programming and Scripting

Global alias does not work in shell script

Hi Linux Set up - alias ls='ls -l' Then run script #! /bin/ksh sub() { ls } sub Is there any way to get it working. I don't want to define alias inside of the program Thank you (2 Replies)
Discussion started by: zam
2 Replies

8. UNIX for Dummies Questions & Answers

tip: Simple script won't run in cygwin - vim editor involved

I ran into this issue and thanks to various postings in various forums, was able to figure out the solution but didn't see one posting that laid the whole issue out cleanly. So thought the following might help others ... ------------------------------------------------------------------------... (2 Replies)
Discussion started by: oxysep
2 Replies

9. UNIX for Dummies Questions & Answers

Simple cron job won't work

I have a script in a directory -say users/me/test/ It looks like this: # "bkup" - copies specified files to the user's ~/Backup # directory after checking for name conflicts. a=$(date +%T) cp $1 ~/test/Backup/$1.$a It copies file.txt from current directory and timestamps the name of it of... (4 Replies)
Discussion started by: coregan
4 Replies

10. UNIX for Dummies Questions & Answers

why won't this Work?

hey programmers! 1-why won't gcc accept as an argument? i tried the recommendations on the man page of getch(),..etc. nothing worked. 2-why it won't see <iostream> && <fstream> even if i implemented the function as follow std::cout<<"..etc"<<endl; 3-after i type this code in it gives... (6 Replies)
Discussion started by: mbabeli
6 Replies
Login or Register to Ask a Question