LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 05:55 AM   #1
Uxhamby
LQ Newbie
 
Registered: Jan 2015
Posts: 19

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, 05:57 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

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

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
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, 06:19 AM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,149

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

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

Original Poster
Rep: Reputation: Disabled
thanks SmallPond

Thanks SmallPond, that is exactly what I needed.

Cheers,

Brian H.
 
Old 05-04-2017, 06:46 PM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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



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 06:25 PM
[SOLVED] bash script: to truncate filename casualzone Linux - Software 3 05-24-2011 10:01 PM
bash script - get filename created by script using variables aolong Linux - General 8 11-19-2009 12:40 PM
changing filename using Bash Script tmbigrigg Programming 10 11-10-2007 07:02 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM

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

All times are GMT -5. The time now is 11:53 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
Open Source Consulting | Domain Registration