alias with variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers alias with variables
# 1  
Old 04-07-2012
Question alias with variables

Hi All,

I'm trying to make an alias with a variable inside.

List:
Code:
#########
# files1 #
# files2 #
# files3 #
# wenk1 #
# wenk2 #
# wenk3 #
#########

Code:
 
alias count='while [ 1 ]
do
ls -ltra | grep {print $1} | wc -l
echo =============
sleep 5
done'

#Input:

count files

#Output should be:

Code:
3
=============

#But, it always comes with an error.

Code:
grep: 0652-033 Cannot open -c}.


--Can you help me out?
--Sorry i'm a newbie Smilie

Thanks in advance. Smilie Smilie


Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Glad you used code tags. Please use them for samples too..

Last edited by Scrutinizer; 04-07-2012 at 10:40 AM..
# 2  
Old 04-07-2012
This shouldn't work:
Code:
grep {print $1}

Please explain what you're trying to achieve.
This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 04-08-2012
Thanks for replying franklin,

I was trying to use the alias like an script.

like when I put:

Code:
count wenk

is displays the count of files:

Code:
3
=============

I also tried to use:

Code:
grep -c {print $1}

And it also doesn't work.
# 4  
Old 04-08-2012
You need to use a function, not an alias:
Code:
count() {
.....
}

Code:
grep {print $1}

You seem to be conflating grep and awk. Like Franklin says: this will never work.
Please explain what you're trying to achieve and what do you mean with a "list" ?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to pass variables into anothother variables?

Below are three variables, which I want to pass into variable RESULT1 username1=userid poihostname1=dellsys.com port1=8080 How can I pass these variables into below code... RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)
Discussion started by: manohar2013
4 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

4. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

5. Homework & Coursework Questions

Creating a .profile, displaying system variables, and creating an alias

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is what I am supposed to do, word for word from my assignment page: 1. Create/modify and print a... (2 Replies)
Discussion started by: Jagst3r21
2 Replies

6. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

7. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

8. UNIX for Dummies Questions & Answers

How to get the alias,when we have the IP.

Hi, I have to set up a printer in the system.Generally the alias is given like sdclbl1 etc.So when I ping i get the IP address. This time they have provided the IP adress.Is there any way to find the alias from this.Ping did not give the alias. Thanks and Regards, Gideon. (2 Replies)
Discussion started by: preethgideon
2 Replies

9. UNIX for Dummies Questions & Answers

alias help

Hi I have a problem when i try to set any thing as alias it works say alias sasa="cd /home/hghgg" but when i close the terminal it does not work (5 Replies)
Discussion started by: shafique
5 Replies
Login or Register to Ask a Question