"$?1 || $<" in csh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers "$?1 || $<" in csh
# 1  
Old 04-02-2010
"$?1 || $<" in csh

Hi:

I am trying to create an alias that takes an argument, but if the argument is missing, gets it from the STDIN. so something like this:

alias foo ' dosomething $?1 || $<'

But obviously it does not work.

What is the typical way to achieve that?

Thanks.

newbie Phil
# 2  
Old 04-02-2010
Something like that is much easier to do as a function that as an alias.

What shell is this?
# 3  
Old 04-02-2010
Quote:
Originally Posted by reborg
Something like that is much easier to do as a function that as an alias.

What shell is this?
Trying to do it in csh.

Thanks.
# 4  
Old 04-02-2010
Hmmm, not the answer I was hoping for, csh doesn't do functions.

Does it really have to be csh? It is quite possible the worst shell to use. If you really have to use csh I would suggest using a script and aliasing the script.

Something like this should work:
Code:
#!/bin/csh

if ($#argv < 1) then
        echo "input filename:"
        set line = $<
        echo "input was $line"
else
        echo "argument was $argv"
endif

# 5  
Old 04-02-2010
Thank you very much for the help!

That is right, there is no reason for me to restrict it to alias only. I will use it as a script then.

A related question is: is "$1" recognized by an alias in csh? I did some experiments, sometime it works and sometime it does not.

Thanks.

Phil
# 6  
Old 04-02-2010
Yes. It should be.
# 7  
Old 04-05-2010
writing scripts in csh/tcsh is pretty much a lost art; with exception of functions, which really is what killed scripting for csh, I find it in a lot of respects better then ksh.. there's things I can do easily in tcsh, it's not so straightforward in ksh, but that's just me.

!$ is from what I can tell what you're looking for, or at least what I've used.
if you type in your alias with an argument, or if you use alias !$ and it takes argv1 from the previous command.

Code:
alias lss 'ls \!$'

%touch file1 file2

%wc -l file1
0 file1

%lss !$
lss file1
file1

%lss file2
file2

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

(CSH basic construct) "@" query

While going through a script, i came across few syntax which I am not aware of what they exactly means. @ cnt = 1 @ num_all = `echo $var` What is the significance of "@" here. What is it called? (3 Replies)
Discussion started by: animesharma
3 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

8. Shell Programming and Scripting

Exactly How can we define "sh ksh csh &bash"

Hi - I m prashant. I m new in UNIX&LINUX world. I want to ask that how can we define the shell in Linux like bash,ksh,csh in Linux. What is the use of these shells. I know there are mny experts on net if you can tell me then please do me this favour and tell me about this topic. ... (1 Reply)
Discussion started by: prashantsingh
1 Replies

9. Shell Programming and Scripting

ksh "while" loop within a csh script

I'm no unix pro for sure, but I have programmed enough other languages to usually get the job done in unix when I have to. I'm currently trying to automate a manual diagnostic process. One of the steps in the manual process generates a file of text output. The next step is running a small... (4 Replies)
Discussion started by: bschnair
4 Replies
Login or Register to Ask a Question