Bash script to delete file input on command line

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Bash script to delete file input on command line
# 1  
Old 07-21-2011
Bash script to delete file input on command line

1) I wrote a script and gave the desired permissions using "chmod 755 scriptname". Now if i edit the script file, why do i need to set the permission again? Didn't i set the permission attribute.. or if i edit the file, does the inode number of file changes?

2) I am running my unix on a server as a client and I am writing a command "ls &", which gives me list of file along with the PID. there is one peculiar pattern i have noticed-- if i give the same command again and again in succession, the PID received increases by some units every time.
My query is, is it just a coincidence that PID increases?

[anisharm@xxx]>cat trmif
if rm $1
echo "$1 file deleted"
[anisharm@xxx]>sh -x -v trmif chessboard
if rm $1
echo "$1 file deleted"
+ rm chessboard
+ echo 'chessboard file deleted'
chessboard file deleted
[anisharm@xxx]>sh -x -v trmif trmif
if rm $1
echo "$1 file deleted"
+ rm trmif
+ echo 'trmif file deleted'
trmif file deleted

In the script above, i am successfully deleting the script file using the same script. How can it be possible? what is the flow of execution for a script file?
I assume the script file info is read first and then executed later on- irrespective of the state of file.
Please help!!SmilieSmilieSmilieSmilieSmilieSmilie

---------- Post updated at 01:50 PM ---------- Previous update was at 11:11 AM ----------

60 views and no answers Smilie
# 2  
Old 07-21-2011
Is this because of SILLY QUERY ?

why dont you analyze and share some informatio here ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Bash script - find command with delete and exec

hi all, i have devised a script that starts in /restored/ and in there, there are a lot of sub folders called peoples names and in the sub folders are files/folders and it deletes the data in the sub folders BUT not the sub folder itself and it should then touch a file in all the sub folders... (3 Replies)
Discussion started by: robertkwild
3 Replies

2. Shell Programming and Scripting

Help in input file's in bash script

hello guys i have bash script to open my routers with username and password i made script but i have problem this script can/t read password from file #!/bin/bash router_file="ips" passwd="password.txt" for router in cat ;$router_file do for pass in cat ;$passwd; do res=$(curl -m 1 ... (7 Replies)
Discussion started by: manhoud
7 Replies

3. Shell Programming and Scripting

Modifying bash script to take each line in a file and execute command

I need to modify a bash script to to take each line in a file and execute command. I currently have this: #!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'`... (3 Replies)
Discussion started by: galford
3 Replies

4. Shell Programming and Scripting

Regarding file input to SQL from command line

Hi friends, Need your help again to get a best approach for the below scenario. I am previously having one shell script which accepts request_id/s as the command line argument. single req_id arg= 1111 Multiple arg= 1111,2222,3333 which gets passed to the embedded sql inside to... (9 Replies)
Discussion started by: Showdown
9 Replies

5. Shell Programming and Scripting

Script to read command line input and change it to some form

Hi, I want to write a small code in which script changes command line input to some form. Example a1 a2 a3 a4 ..... output should be "a1|a2|a3|....." Number of inputs in command line can be any variable (2 Replies)
Discussion started by: Raza Ali
2 Replies

6. Shell Programming and Scripting

Read input file with in awk script not through command line

Hi All, Do we know how to read input file within awk script and send output toanother log file. All this needs to be in awk script, not in command line. I am running this awk through crontab. Cat my.awk #!/bin/awk -f function test(var){ some code} { } END { print"test code" } (5 Replies)
Discussion started by: random_thoughts
5 Replies

7. Shell Programming and Scripting

Shell script to input as if from command line to the java program

Hi, We are having a java server which can run on command line and once initiated, it will prompt options to enter from 0 to 5. The java program kickoff respective operation once number is entered between 0 to 5. However i want to always enter "1" and write another shell program wrapper to start... (4 Replies)
Discussion started by: surya5kn
4 Replies

8. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

9. Shell Programming and Scripting

Input file to bash script

Hi, I have this script #!/bin/sh sed 's,\,,g' input.dat > output .dat But i want to run it witb different files. So i want the input file as an input argument to the script, how could i do that. Running it like this: > input.dat (2 Replies)
Discussion started by: Johanni
2 Replies

10. Shell Programming and Scripting

How can I send the input of a read line command through a shell script

Hi All, I wish to automate the unix command 'su' through a shell script. I would like to pass the content of a file as password to 'su' command. My script is as below, #! /bin/sh su userA while read line do rpm -ivh $line done < pwd.txt where pwd.txt contains the password of... (6 Replies)
Discussion started by: little_wonder
6 Replies
Login or Register to Ask a Question