How can I have one script with 2 different names?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How can I have one script with 2 different names?
# 8  
Old 05-15-2010
Maybe you're thinking about the ln command is a little skewed?

Soft or Symbolic links DO NOT create a second file. The ln utility creates a secondary reference to a given file...with a system-wide permanance that aliases do not have; extremely useful since many of the basic utils in the system are oftentimes actually links...not direct references. I also use them to overload a given script so that it behaves differently according to its $0 name.

Code:
$ ln -s file.csv file.lnk
$ ls -ltr file.*
-rw-rw-r--  1 curleb   sys       554352 May 11 15:57 file.cpy
-rw-rw-r--  1 curleb   sys        76392 May 11 16:07 file.csv
lrwxrwxrwx  1 curleb   sys            8 May 15 18:12 file.lnk -> file.csv

Notice that the soft-link created is not actually a second file, but just a systemic shortcut. Does this help any?
# 9  
Old 05-15-2010
Further to curleb, a common example of hard links is "ls" itself.

In this example /usr filesystem inode 1244 has 7 different names (hence the link count of 7) but there is only one program. The program behaves differently according to how it is called.

Code:
ls -lisad /usr/bin/ls
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/ls

find /usr/ -xdev -inum 1244 -exec ls -lisad {} \;
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/l
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/lc
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/ll
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/ls
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/lsf
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/lsr
  1244   64 -r-xr-xr-x   7 bin        bin          28672 Nov 14  2000 /usr/bin/lsx

# 10  
Old 05-15-2010
and even 90 hardlinks to a single executable on Solaris (isaexec based binaries)
Code:
$ uname -a
SunOS m10 5.11 snv_134 i86pc i386 i86pc
$ find /usr/bin -inum $(ls -i /usr/bin/uptime|nawk '{print $1}') | wc -l
90

# 11  
Old 05-19-2010
curleb ,
Very useful!
Thank you so much!
Got it!
Thank you so much!

Last edited by lemon_06; 05-20-2010 at 12:12 AM..
# 12  
Old 05-19-2010
Code:
ln -s script_a script_b

# 13  
Old 05-26-2010
i have the same situation
where one script : two different names : two diffferent outcome? ( first is to email to myself -done this part ) second is to display onto the terminal

thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Long file names within shell script

I am downloading a zip file that contain files that are very long. I am trying to process them, but cannot. I can move the files from one directory to another at the shell prompt, but not within a shell script, I get a stat error. The files look somewhat like this; ... (5 Replies)
Discussion started by: trolley
5 Replies

2. Shell Programming and Scripting

Script to change file names

I have a landing directory on my unix (solaris) server, that receives the following files: MLH4301I AAOT-hhslog.610.20150805.txt MLH4301I AAOT-hhslog.611.20150805.txt MLH4301I AAOT-hhslog.612.20150805.txt MLH4301I AAOT-hhslog.613.20150805.txt and I need to add to this files the number 10000... (6 Replies)
Discussion started by: fretagi
6 Replies

3. Shell Programming and Scripting

Selecting/using part of directory names in script

I'm making a shell script to: -copy directories to a new location -perform conversions on the files within the copied directories -move the newly created files to a new directory Please see my super basic script and notes below... and thank you thank you thank you in advance !! ... (1 Reply)
Discussion started by: kayzee
1 Replies

4. Shell Programming and Scripting

Problems with script to find file names

Have a text file "test-array.txt" with contents below a23003 b23406 c23506 Tying to read the above file into an array and search for file-names in a directory TEST_DIR ,recursively with the above names in them. Example: If TEST_DIR has a files named xyxa_a23003_test.sql,... (4 Replies)
Discussion started by: gaurav99
4 Replies

5. UNIX for Advanced & Expert Users

script regarding listing long group names

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (1 Reply)
Discussion started by: mike12
1 Replies

6. Shell Programming and Scripting

input file names to a script

What is a more efficient way to read files into a script? I don't want to hard code the file names like below: for file in file1 \ file2 do ... done I want to execute the script with a variable number for files for input like below: ./scriptname file1 file2 file3 ...... (3 Replies)
Discussion started by: djehresmann
3 Replies

7. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies

8. Shell Programming and Scripting

script to find function names

hi, i am a newbie and have to write a rather complicated script. Assume that i have a variable called x and a C source code file say file1.c (these are the inputs of the script) and i need to find the names of all the functions in the C file containing x.Take the following code as an example: ... (2 Replies)
Discussion started by: samantha grace
2 Replies

9. Shell Programming and Scripting

How to get files names passed to a script

I need to get files names passed to a script. Here number of files passed may vary like MyScript.ksh file1 file2 file3..... so on I am writting script somthing like this set -A Files while (i<=$#) do File=$i let i=i+1 done Is this correct way doing this. Is there any other way.... (5 Replies)
Discussion started by: unishiva
5 Replies

10. Shell Programming and Scripting

Script for file names/sizes

How can I look at a certain directory and list all the file names, locations and sizes of each file in the current directory and all subdirectories? (2 Replies)
Discussion started by: ssmiths001
2 Replies
Login or Register to Ask a Question