Script that does not change itself

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that does not change itself
# 1  
Old 10-05-2013
Script that does not change itself

I have a script that makes inline replacements to other scripts in a given directory: it loops through all files with extension "sh". What is a standard way of preventing that the script does not change itself ($0)?
# 2  
Old 10-05-2013
What utility is used to process your script (such as awk, sed, bash, or ksh)?

Show us the loop in your script that processes your *.sh files.
# 3  
Old 10-05-2013
The file edited for brevity looks as follows:

for file in *.sh
   # identify file extension
   # one space after the '#'
   sed -i '' -e 's/#/# /' $file
   sed -i '' -e 's/#  /# /' $file

# 4  
Old 10-05-2013
should you be using bash (which Don Cragu asked for), extended pattern matching might work:
shopt -s extglob
for i in !(${0#*/}); do echo $i; done

EDIT: or some grep -v $0 in the for loop.
# 5  
Old 10-05-2013
You could just exclude the running script file:
for n in *.sh; do
	if [[ "$n" != `basename $0` ]]; then
		echo $n

# 6  
Old 10-05-2013
I like this solution because it requires a mere addition to the for loop without additional indentation:
Originally Posted by RudiC
or some grep -v $0 in the for loop.
# 7  
Old 10-05-2013
As an alternative to the cool script solutions, could you simply name the script file different - not ending with .sh - or move it to a different directory?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help on script to change permissions

Hi All I have the following script that is supposed to change permissions of incoming files to a directory, but it does not seem to do what I want, please can you help: mkdir -p /tmp/tmpdir find /moneta_polled01/sgsn/ -exec ls -l {} \; |grep -v rwxrwxrwx |awk '{print $9}' >... (4 Replies)
Discussion started by: fretagi
4 Replies

2. UNIX for Dummies Questions & Answers

Script to change file name

Hi, I need to write a script that changes the name of the filename. Let's say my script is named change_filename and I want to use it on a file named test1.txt. After running the script I want the filename renamed to test1_fails.txt e.g. $ ls test1.txt test2.txt test3.txt $ ... (15 Replies)
Discussion started by: millsy5
15 Replies

3. Shell Programming and Scripting

Change Parse Script

I have a question about changing how parsing occurs currently for us: input FILE123 TAGA01: 01 TAG02: daadsf TAG03: adfasdf TAGBBB04: 35 TAG05: asdfa TAG07: adfd TAG07: adfa3 TAG07: 234234 TAGCC08: 3525df TAG09: adsfa TAG10: 245 TAG11: nnnn EOR: TAGA01: 02 TAG02: abas TAG03:... (2 Replies)
Discussion started by: Roga Danar
2 Replies

4. Shell Programming and Scripting

Shell Script to change a user password using script

Hi Experts, I had tried to executes this script to change the user password through script: No lines in buffer #!/bin/ksh cat /etc/passwd | grep -v userid >> /tmp/pass.tmp1 cat /etc/passwd | grep userid >> /tmp/pass.tmp2 PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2` PASS2=`q2w3e4r5` sed... (3 Replies)
Discussion started by: indrajit_renu
3 Replies

5. UNIX for Dummies Questions & Answers

how to change argument of an script

Hello every one i have an script in sco unix 5.06 to take a long archive over MOD drive and this script contains many line to change destination to DVD anyone can help to me for change this script to take backup on DVD instead of MOD the attached script LzaModBed.engl (1 Reply)
Discussion started by: kaydream
1 Replies

6. Shell Programming and Scripting

Change the Windows Batch script to UNIX shell script.

Hi, When I run the below script in UNIX it's throwing syntax errors. Actually it's a windows batch script. Could anyone change the below Windows Batch script to UNIX shell script... Script: REM :: File Name : Refresh_OTL.bat REM :: Parameters : %1 - Region REM :: : %2 - Cube Type REM ::... (5 Replies)
Discussion started by: tomailraj
5 Replies

7. Shell Programming and Scripting

need inputs on how i can change my script to reduce amount of time the script takes

HI , I have a list1 which consists of data that i have to search and a list2 which has the files that need to be searched .So basically i am using list1 on list2 to see if list1 data is present if found replace it .I have written the code using foreach loop for each list .This is taking the... (1 Reply)
Discussion started by: madhul2002
1 Replies

8. Shell Programming and Scripting

Change Directory via a script?

I would like to have a script that would change my current working directory. However, any time I execute a 'cd' command in a script, it holds only for the life of that script -- the working directory on exit is the same as when the script was initiated. Is it possible to have the script return... (3 Replies)
Discussion started by: George Borrmann
3 Replies

9. Shell Programming and Scripting

How do I change users in a script???

Hi there, Does anyone know of a way I can become a different user in a script? I need to run a script as one user (not root), and change to another user half way through. It stops and asks me for the password, and I can't find a way to feed the password in through the script. Thanks (2 Replies)
Discussion started by: chorgan
2 Replies
Login or Register to Ask a Question