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
# 15  
Old 05-21-2010
rather than leave it 'sticky' as you've described, why not assume you'll want a semblance of dynamic assignment and want to name a portion of the file name each time, and leave the alias to decipher which extension you're looking for:

Code:
% ls -log ~/file*
-rw-r--r--   1      48 May 12 13:48 /export/home/curleb/file.csv
-rw-rw----   1      10 May 12 16:27 /export/home/curleb/file.wri

% cat file.csv
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6

% alias ss 'cat ~/\!:1\.csv '

% alias tt 'cat ~/\!:1\.txt '

% alias yy 'cat ~/\!:1\.cpy '

% ss file
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6

% tt file
cat: cannot open /export/home/curleb/file.txt

% yy file
cat: cannot open /export/home/curleb/file.cpy

You could even go so far as to incorporate a wildcard into the alias, but this could get sketchy if there's multiple file's that could get globbed together.

On a side note: csh bad! Smilie
# 16  
Old 05-21-2010
Curleb: I would prefer to leave it 'sticky' rather than typing the filename every time I run the alias. The ratio of running alias to defining alias is 50:1. So, I will save myself typing the filename 50 times if the alias is 'sticky' kind.

I know csh is bad but I am kinda stuck with it for now. As I am new, I can't venture moving into another shell while I am still learning c shell.
# 17  
Old 05-21-2010
I hear you. So, let's make it sticky...
Code:
% alias sticky 'set target="\!:1" '

% sticky file

% echo $target
file

% alias ss 'cat ~/$target\.csv '

% ss
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6

% sticky nofile

% ss
cat: cannot open /export/home/curleb/nofile.csv

But...just so you don't dally too long in csh, and ramp up to some other shell:http://www.grymoire.com/Unix/CshTop10.txt
# 18  
Old 05-21-2010
Hi, Once I tried to use Aliases to get logs from applications but i coudlnt make Aliases run properly even i tried too many things. So maybe u should give up like i did and try to write simple scripts and put the path of scripts into the PATH in .profile.
here the link, maybe it helps:

https://www.unix.com/shell-programmin...many-logs.html

regards
# 19  
Old 05-21-2010
Quote:
Originally Posted by curleb
I hear you. So, let's make it sticky...
Code:
% alias sticky 'set target="\!:1" '

% sticky file

% echo $target
file

% alias ss 'cat ~/$target\.csv '

% ss
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6
1,2,3,4,5,6

% sticky nofile

% ss
cat: cannot open /export/home/curleb/nofile.csv

But...just so you don't dally too long in csh, and ramp up to some other shell:http://www.grymoire.com/Unix/CshTop10.txt
Excellent. Got it working the way I wanted. I put the alias al in .cshrc file as suggested and then 3 more aliases using the $target as the dynamic value. Here is what I did:

alias al 'set target="\!:1" '
alias s 'vi ~/$target\.csv'
alias t 'vi ~/$target\.txt'
alias l 'vi ~/$target\.log'

I run alias al once with the filename parameter and then use aliases s,t and l as many times as I want. To change the filename to something else, just use alias al again with the new filename.

Thanks a lot for all the help you provided.

Now, just for my education, I still don't understand why the alias assignment doesn't work in the script file (al script) and it works from .cshrc file. Will certainly help me understand unix better.
# 20  
Old 05-21-2010
EAGLE:

Not to question methyl's entirely valid advice in the other thread, you'd happened to mix and match syntaxes in your previous thread (upon the advise of another poster)...so you weren't necessarily processing with the proper aliases, hence your issues. I'm no fan of csh, of course, but this error makes it a moot point to the discussion here. If you're processing okay with methyl's suggestion, good on you.

I've left comment back there as well...

---------- Post updated at 15:03 ---------- Previous update was at 14:57 ----------

sssccc: I would plead the fifth on that one... From this distance...it just looks like you've got a bum shell.

Get a new one that polishes up nicer...! Smilie
# 21  
Old 05-22-2010
MySQL

Quote:
Originally Posted by sssccc
Tried that. Still no go. Same message.
Code:
[root@rhnserver ~]# echo $shell
/bin/tcsh

Code:
[root@rhnserver ~]# cat t.csh
#!/bin/csh
echo Setting alias....
alias ss "vi myfile.log"

Code:
[root@rhnserver ~]# alias
cp      cp -i
l.      ls -d .* --color=tty
ll      ls -l --color=tty
ls      ls --color=tty
mv      mv -i
rm      rm -i

Code:
[root@rhnserver ~]# source t.csh
Setting alias....

Code:
 
[root@rhnserver ~]# alias
cp      cp -i
l.      ls -d .* --color=tty
ll      ls -l --color=tty
ls      ls --color=tty
mv      mv -i
rm      rm -i
ss      vi myfile.log


Regards
ygemici
 
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