LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy
User Name
Password
Puppy This forum is for the discussion of Puppy Linux.

Notices


Reply
  Search this Thread
Old 05-04-2017, 06:55 AM   #1
Uxhamby
LQ Newbie
 
Registered: Jan 2015
Posts: 11

Rep: Reputation: Disabled
Pid in bash script filename?


How can i have a bash script use its pid number as part of a file name?

Thanks.

Brian H
 
Old 05-04-2017, 06:57 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,904

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
can you please give us more details/some example?
 
Old 05-04-2017, 07:16 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,430

Rep: Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938Reputation: 1938
A PID is assigned when the process is created i.e. when your script is executed and will not be the same if you run it again. Most services create a pid file which is deleted when it is stopped by the init system.

So can you explain why you want to use the PID as part of the file name? You can find its pid using the pidof command.
 
Old 05-04-2017, 07:19 AM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,855

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
The pid is $$ so you can create a filename as

Code:
FIL=$$.txt
 
1 members found this post helpful.
Old 05-04-2017, 07:28 PM   #5
Uxhamby
LQ Newbie
 
Registered: Jan 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
thanks SmallPond

Thanks SmallPond, that is exactly what I needed.

Cheers,

Brian H.
 
Old 05-04-2017, 07:46 PM   #6
hydrurga
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.2 MATE
Posts: 3,491
Blog Entries: 2

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Glad you solved your problem, Uxhamby.

Could you please mark the thread as "Solved" (see "Thread Tools" at the top of the thread). Cheers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to increment a filename jpv50 Programming 13 07-01-2015 07:25 PM
[SOLVED] bash script: to truncate filename casualzone Linux - Software 3 05-24-2011 11:01 PM
bash script - get filename created by script using variables aolong Linux - General 8 11-19-2009 01:40 PM
changing filename using Bash Script tmbigrigg Programming 10 11-10-2007 08:02 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration