Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

You are an insult to my intelligence! I demand that you log off immediately.


devel / comp.unix.shell / Re: Wrote a bash script to create and add a swapfile

SubjectAuthor
* Wrote a bash script to create and add a swapfileCecil Westerhof
+* Re: Wrote a bash script to create and add a swapfileBen Bacarisse
|`* Meta re: the state of the economy and various other topics (Was: Wrote a bash scKenny McCormack
| +* Re: Meta re: the state of the economy and various other topicsAragorn
| |`- Re: Meta re: the state of the economy and various other topicsCecil Westerhof
| `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|  `* Re: Meta re: the state of the economy and various other topicsEd Morton
|   `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|    `* Re: Meta re: the state of the economy and various other topicsEd Morton
|     `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|      +- Re: Meta re: the state of the economy and various other topicsKenny McCormack
|      `* Re: Meta re: the state of the economy and various other topicsEd Morton
|       `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|        `* Re: Meta re: the state of the economy and various other topicsEd Morton
|         `- Re: Meta re: the state of the economy and various other topicsPercival John Hackworth
+* Re: Wrote a bash script to create and add a swapfileAuric__
|`* cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfCecil Westerhof
| `* Re: cross-post, or multi-post Was: Re: Wrote a bash script toAragorn
|  `* Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a sCecil Westerhof
|   +* Re: cross-post, or multi-post Was: Re: Wrote a bash script to createDavid W. Hodgins
|   |`- Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a sAuric__
|   `- Re: cross-post, or multi-postHelmut Waitzmann
+* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|+* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||+* Re: Wrote a bash script to create and add a swapfileEd Morton
|||+* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
||||+* Re: Wrote a bash script to create and add a swapfileKenny McCormack
|||||+- Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|||||`- Re: Wrote a bash script to create and add a swapfileGeoff Clare
||||`* Re: Wrote a bash script to create and add a swapfileAnssi Saari
|||| `- Re: Wrote a bash script to create and add a swapfileLew Pitcher
|||`- Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||`* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|| `* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||  `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
||   `* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||    `- Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
|`* Re: Wrote a bash script to create and add a swapfileEd Morton
| +- Re: Wrote a bash script to create and add a swapfileKenny McCormack
| +* Re: Wrote a bash script to create and add a swapfileAragorn
| |+- Re: Wrote a bash script to create and add a swapfileEd Morton
| |`* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
| | `* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
| |  `- Re: Wrote a bash script to create and add a swapfileCecil Westerhof
| `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|  `* Re: Wrote a bash script to create and add a swapfileEd Morton
|   `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|    `- Re: Wrote a bash script to create and add a swapfileEd Morton
`* Re: Wrote a bash script to create and add a swapfileKaz Kylheku
 `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
  `* Re: Wrote a bash script to create and add a swapfilegerg
   `- Re: Wrote a bash script to create and add a swapfileJanis Papanagnou

Pages:123
Re: Meta re: the state of the economy and various other topics

<tdj3qo$fpck$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5663&group=comp.unix.shell#5663

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 11:08:56 -0500
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <tdj3qo$fpck$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <87zgg49juu.fsf@munus.decebal.nl>
<tditm4$f9b6$1@dont-email.me> <875yiqan1p.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 16:08:56 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="517524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Kg1kCXycFxIdJrslrqu0l"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:ADbkfXz4+3VaG3SNNUbCvQoSQ9M=
Content-Language: en-US
X-Antivirus-Status: Clean
X-Antivirus: Avast (VPS 220817-4, 8/17/2022), Outbound message
In-Reply-To: <875yiqan1p.fsf@munus.decebal.nl>
 by: Ed Morton - Wed, 17 Aug 2022 16:08 UTC

On 8/17/2022 10:48 AM, Cecil Westerhof wrote:
> Ed Morton <mortonspam@gmail.com> writes:
>
>> On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
>> <snip>
>>> I created a bash group on LinkedIn and there was a question about how
>>> to learn to program in bash. So I wrote a script and an article
>>> explaining the script with hopefully interesting tips for people how
>>> to create their own scripts.
>>> I just thought/hoped it could be interesting for people using this
>>> newsgroup.
>>
>> Then I wish you had posted your script and article here and pointed
>> people from LinkedIn here instead of doing it the other way around.
>
> I do not think that will work. I love usenet, but we (users of usenet)
> are a dying race. Most people do not even know it exists.
>

Usenet was just one example of an existing forum, if you don't like
usenet pick one of the many other existing forums to post your script
and explanation on. StackExchange and StackOverflow seem to me to be the
most popular these days, but idk, there's lots to choose from. The point
was to not introduce yet another forum for people to have to search for
answers.

Ed.

Re: Wrote a bash script to create and add a swapfile

<87wnb697uy.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5664&group=comp.unix.shell#5664

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 18:01:57 +0200
Organization: Decebal Computing
Lines: 49
Message-ID: <87wnb697uy.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="525100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eMx6CnbVZ+I7zv6k1OnpHiMT6GFMOEdI="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:94AoKYDVlElqJh3LbT/bqVFxf14=
sha1:y5rvafctJP2U+jljLWjzw7cKU3I=
 by: Cecil Westerhof - Wed, 17 Aug 2022 16:01 UTC

Ed Morton <mortonspam@gmail.com> writes:

> On 8/16/2022 12:37 PM, Cecil Westerhof wrote:
>> Cecil Westerhof <Cecil@decebal.nl> writes:
>>
>>> For people who know Bash, but like to learn write (better) scripts I
>>> wrote an article about a script I wrote to create and add a swapfile:
>>> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>>>
>>> You can get the script here:
>>> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh
>> The script my post explains.
>
> You should copy/paste your script into http://shellcheck.net and fix the
> issues it tells you about (e.g. the missing quotes in several places).

I did not know that. I am going to try this out.

> A few additional things I noticed:
>
> You're using `{...}` unnecessarily everywhere, I think maybe you're
> mistaking what curly brackets do (just separate a variable from
> concatenated text) vs what double quotes do (protect your variable from
> globbing, word splitting, and filename expansion).

I know that people they are not necessary, but try:
dummy='some text'
echo ${dummy}12
echo $dummy12

And yes, you said separate from concatenated text, but I have seen it
go wrong to often. And in a way find it also looking better.

> The use of `function foo {` is non-portable, use `foo() {` instead.

It is a bash script, so it is in my opinion the preferred way.

> When printing error messages (e.g. inside "giveError()") add `>&2` so
> the message goes to stderr instead of stdout.

Yes, I already noticed that blunder.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Meta re: the state of the economy and various other topics

<87sflu9651.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5665&group=comp.unix.shell#5665

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 18:39:06 +0200
Organization: Decebal Computing
Lines: 30
Message-ID: <87sflu9651.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <87zgg49juu.fsf@munus.decebal.nl>
<tditm4$f9b6$1@dont-email.me> <875yiqan1p.fsf@munus.decebal.nl>
<tdj3qo$fpck$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="531172"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pfy8kPJsHUnEIcXEjtBYKFuBDXIY0KXE="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:KnK267+Gj4xBEFu9JhvLq7PUcc8=
sha1:xZl7Vn0wR2150ba1Jj9BTe4B/EE=
 by: Cecil Westerhof - Wed, 17 Aug 2022 16:39 UTC

Ed Morton <mortonspam@gmail.com> writes:

> On 8/17/2022 10:48 AM, Cecil Westerhof wrote:
>> Ed Morton <mortonspam@gmail.com> writes:
>>
>>> On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
>>> <snip>
>>>> I created a bash group on LinkedIn and there was a question about how
>>>> to learn to program in bash. So I wrote a script and an article
>>>> explaining the script with hopefully interesting tips for people how
>>>> to create their own scripts.
>>>> I just thought/hoped it could be interesting for people using this
>>>> newsgroup.
>>>
>>> Then I wish you had posted your script and article here and pointed
>>> people from LinkedIn here instead of doing it the other way around.
>> I do not think that will work. I love usenet, but we (users of usenet)
>> are a dying race. Most people do not even know it exists.
>>
>
> Usenet was just one example of an existing forum, if you don't like
> usenet

What in the sentence 'I love usenet' did you make think that I do not
like it?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Meta re: the state of the economy and various other topics

<tdj6cc$9kgf$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5666&group=comp.unix.shell#5666

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!3.us.feeder.erje.net!feeder.erje.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 16:52:28 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tdj6cc$9kgf$1@news.xmission.com>
References: <874jyccqbs.fsf@munus.decebal.nl> <875yiqan1p.fsf@munus.decebal.nl> <tdj3qo$fpck$1@dont-email.me> <87sflu9651.fsf@munus.decebal.nl>
Injection-Date: Wed, 17 Aug 2022 16:52:28 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="315919"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 17 Aug 2022 16:52 UTC

In article <87sflu9651.fsf@munus.decebal.nl>,
Cecil Westerhof <Cecil@decebal.nl> wrote:
....
>> Usenet was just one example of an existing forum, if you don't like
>> usenet
>
>What in the sentence 'I love usenet' did you make think that I do not
>like it?

Cecil, you are trying to make sense of the ravings of a lunatic.

--
When someone tells me he/she is a Christian I check to see if I'm
still in possession of my wallet.

Re: Wrote a bash script to create and add a swapfile

<tdj6k8$g6be$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5667&group=comp.unix.shell#5667

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 11:56:40 -0500
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <tdj6k8$g6be$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
<87wnb697uy.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 16:56:40 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="530798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ATXRYn5VgGPgelrbbZYp9"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:1ClibZ8YmEpGGQRtdQEJtUDit6c=
In-Reply-To: <87wnb697uy.fsf@munus.decebal.nl>
X-Antivirus: Avast (VPS 220817-4, 8/17/2022), Outbound message
Content-Language: en-US
X-Antivirus-Status: Clean
 by: Ed Morton - Wed, 17 Aug 2022 16:56 UTC

On 8/17/2022 11:01 AM, Cecil Westerhof wrote:
> Ed Morton <mortonspam@gmail.com> writes:
<snip>
>> The use of `function foo {` is non-portable, use `foo() {` instead.
>
> It is a bash script, so it is in my opinion the preferred way.

I see, so this apparently falls into the "but not rigorously" side of
your previous comment:

> In a way I like to confirm to POSIX. But not rigorously.

:-).

Obviously bash accepts either format and has no preference/distinction
in itself so which one to use in a bash script just depends on which
other shell(s) you want your code to be compatible with.

If you want your code to be compatible with ksh then, depending on what
you want it to mean in an AT&T implementation of ksh, you should use
`function name` or `name ()`, with zsh then you can use either, or with
all Bourne-derived shells including zsh and ksh (with caveats) then
`name ()`.

If you don't care about any of that then why not just make it the most
portable, `name ()`, especially since you're providing it as an example
for others to emulate and they might be trying to implement similar
functions in other shells.

Ed.

Re: Meta re: the state of the economy and various other topics

<tdj6la$g6be$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5668&group=comp.unix.shell#5668

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 11:57:14 -0500
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <tdj6la$g6be$2@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <87zgg49juu.fsf@munus.decebal.nl>
<tditm4$f9b6$1@dont-email.me> <875yiqan1p.fsf@munus.decebal.nl>
<tdj3qo$fpck$1@dont-email.me> <87sflu9651.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 16:57:14 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="530798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gsr04J0b3EK6hNADHtZI6"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:jqq28+E0RWPJwW+dpA8W9oxdiP0=
In-Reply-To: <87sflu9651.fsf@munus.decebal.nl>
X-Antivirus: Avast (VPS 220817-4, 8/17/2022), Outbound message
Content-Language: en-US
X-Antivirus-Status: Clean
 by: Ed Morton - Wed, 17 Aug 2022 16:57 UTC

On 8/17/2022 11:39 AM, Cecil Westerhof wrote:
> Ed Morton <mortonspam@gmail.com> writes:
>
>> On 8/17/2022 10:48 AM, Cecil Westerhof wrote:
>>> Ed Morton <mortonspam@gmail.com> writes:
>>>
>>>> On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
>>>> <snip>
>>>>> I created a bash group on LinkedIn and there was a question about how
>>>>> to learn to program in bash. So I wrote a script and an article
>>>>> explaining the script with hopefully interesting tips for people how
>>>>> to create their own scripts.
>>>>> I just thought/hoped it could be interesting for people using this
>>>>> newsgroup.
>>>>
>>>> Then I wish you had posted your script and article here and pointed
>>>> people from LinkedIn here instead of doing it the other way around.
>>> I do not think that will work. I love usenet, but we (users of usenet)
>>> are a dying race. Most people do not even know it exists.
>>>
>>
>> Usenet was just one example of an existing forum, if you don't like
>> usenet
>
> What in the sentence 'I love usenet' did you make think that I do not
> like it?
>

I mean "like" in the context of where to post your script.

Re: Wrote a bash script to create and add a swapfile

<87k07695mp.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5669&group=comp.unix.shell#5669

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 18:50:06 +0200
Organization: Decebal Computing
Lines: 15
Message-ID: <87k07695mp.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
<20220817170126.7dcb0795@nx-74205>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="534233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RQbZYSzxwfjoRG/rywJ3VqhekSxUF3Vc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:YErmiKb+OzTHceATGXSpw6jUmLc=
sha1:026OI4VbzO2kcXhqNY5ilsQOEEk=
 by: Cecil Westerhof - Wed, 17 Aug 2022 16:50 UTC

Aragorn <thorongil@telenet.be> writes:

> I agree with that, and I myself always write my scripts in the most
> portable way, but the OP has very clearly indicated that it is a bash
> script, and that it's specifically intended for use in GNU/Linux, where
> GNU bash is still the main shell.

I have heard of people that used my bash library on a non Linux
system, but it is a very small minority. I myself work only with
Linux.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<87o7wi95v6.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5670&group=comp.unix.shell#5670

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 18:45:01 +0200
Organization: Decebal Computing
Lines: 27
Message-ID: <87o7wi95v6.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<tdiukl$f9b7$2@dont-email.me> <871qteamv5.fsf@munus.decebal.nl>
<tdj3kg$9is2$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="534233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+73GqS+mEDzJpCw7HU8QHgnDGcVPpvT+g="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:lgfA8OK9X8sQOZcQ6x2xo8Gqfgo=
sha1:kZZmNsBDevD0TKtpw6PlYYGDqSw=
 by: Cecil Westerhof - Wed, 17 Aug 2022 16:45 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:

> In article <871qteamv5.fsf@munus.decebal.nl>,
> Cecil Westerhof <Cecil@decebal.nl> wrote:
> ...
>>> awk '{p=$4} END{print substr(p, 1, length(p) - 1)}'
>>
>>For me it works, but I should implement something like this then.
>
> Or you could just use either mawk or gawk, which are known to work.
>
> I always recommend against using plain old "awk" in a script, b/c you never
> know what you are going to get.
>
> Until fairly recently, using plain "awk" under Solaris got you a very old,
> essentially non-functional version of AWK.

But awk is much more often installed as mawk, or gawk. So that is why
I always use awk. Until know no complaints. But maybe that is because
nobody uses my scripts. :-D

On my system I have both mawk and gawk and awk is silently just gawk.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Meta re: the state of the economy and various other topics

<874jya93sk.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5671&group=comp.unix.shell#5671

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 19:29:47 +0200
Organization: Decebal Computing
Lines: 43
Message-ID: <874jya93sk.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <87zgg49juu.fsf@munus.decebal.nl>
<tditm4$f9b6$1@dont-email.me> <875yiqan1p.fsf@munus.decebal.nl>
<tdj3qo$fpck$1@dont-email.me> <87sflu9651.fsf@munus.decebal.nl>
<tdj6la$g6be$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="543387"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19l1F6yyXJHfFamzAOAHk1kpsmlHAoah7c="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:vU0u1Sa4pefXYF2++9rcE6BIyTY=
sha1:DhfaHS5SM/J3yhqBlzh9lnkyc4Y=
 by: Cecil Westerhof - Wed, 17 Aug 2022 17:29 UTC

Ed Morton <mortonspam@gmail.com> writes:

> On 8/17/2022 11:39 AM, Cecil Westerhof wrote:
>> Ed Morton <mortonspam@gmail.com> writes:
>>
>>> On 8/17/2022 10:48 AM, Cecil Westerhof wrote:
>>>> Ed Morton <mortonspam@gmail.com> writes:
>>>>
>>>>> On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
>>>>> <snip>
>>>>>> I created a bash group on LinkedIn and there was a question about how
>>>>>> to learn to program in bash. So I wrote a script and an article

And this is why I posted it there and not here.

>>>>>> explaining the script with hopefully interesting tips for people how
>>>>>> to create their own scripts.
>>>>>> I just thought/hoped it could be interesting for people using this
>>>>>> newsgroup.
>>>>>
>>>>> Then I wish you had posted your script and article here and pointed
>>>>> people from LinkedIn here instead of doing it the other way around.
>>>> I do not think that will work. I love usenet, but we (users of usenet)
>>>> are a dying race. Most people do not even know it exists.
>>>>
>>>
>>> Usenet was just one example of an existing forum, if you don't like
>>> usenet
>> What in the sentence 'I love usenet' did you make think that I do not
>> like it?
>>
>
> I mean "like" in the context of where to post your script.

I like to post it here, but it is not only about like, it is also
about being effective. It is not opportune to answer a question in the
LinkedIn bash group on usenet.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<87zgg27op0.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5672&group=comp.unix.shell#5672

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 19:41:15 +0200
Organization: Decebal Computing
Lines: 20
Message-ID: <87zgg27op0.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
<87wnb697uy.fsf@munus.decebal.nl> <tdj6k8$g6be$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="543387"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pUHAUA0CJlM7uQLETS3v/reToGAw7ZXc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:sRMg6pHQlYzL3r//ncHeUbukq0k=
sha1:kkvHxFS7bSqcA2JUdslfhrSLma0=
 by: Cecil Westerhof - Wed, 17 Aug 2022 17:41 UTC

Ed Morton <mortonspam@gmail.com> writes:

> If you want your code to be compatible with ksh then, depending on
> what

No, I do not want that.

> If you don't care about any of that then why not just make it the most
> portable, `name ()`, especially since you're providing it as an example
> for others to emulate and they might be trying to implement similar
> functions in other shells.

You would have preferred that everyone used BASICODE?
https://en.wikipedia.org/wiki/BASICODE

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Meta re: the state of the economy and various other topics

<tdjbku$gpjv$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5673&group=comp.unix.shell#5673

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 13:22:23 -0500
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <tdjbku$gpjv$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <87zgg49juu.fsf@munus.decebal.nl>
<tditm4$f9b6$1@dont-email.me> <875yiqan1p.fsf@munus.decebal.nl>
<tdj3qo$fpck$1@dont-email.me> <87sflu9651.fsf@munus.decebal.nl>
<tdj6la$g6be$2@dont-email.me> <874jya93sk.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 18:22:22 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="550527"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ntc2doEEDi8F1vy5Snn8R"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:lrytqEqYO7hGOdGcBOk/+2eYb/8=
X-Antivirus: Avast (VPS 220817-6, 8/17/2022), Outbound message
In-Reply-To: <874jya93sk.fsf@munus.decebal.nl>
X-Antivirus-Status: Clean
Content-Language: en-US
 by: Ed Morton - Wed, 17 Aug 2022 18:22 UTC

On 8/17/2022 12:29 PM, Cecil Westerhof wrote:
> Ed Morton <mortonspam@gmail.com> writes:
>
>> On 8/17/2022 11:39 AM, Cecil Westerhof wrote:
>>> Ed Morton <mortonspam@gmail.com> writes:
>>>
>>>> On 8/17/2022 10:48 AM, Cecil Westerhof wrote:
>>>>> Ed Morton <mortonspam@gmail.com> writes:
>>>>>
>>>>>> On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
>>>>>> <snip>
>>>>>>> I created a bash group on LinkedIn and there was a question about how
>>>>>>> to learn to program in bash. So I wrote a script and an article
>
> And this is why I posted it there and not here.
>
>
>>>>>>> explaining the script with hopefully interesting tips for people how
>>>>>>> to create their own scripts.
>>>>>>> I just thought/hoped it could be interesting for people using this
>>>>>>> newsgroup.
>>>>>>
>>>>>> Then I wish you had posted your script and article here and pointed
>>>>>> people from LinkedIn here instead of doing it the other way around.
>>>>> I do not think that will work. I love usenet, but we (users of usenet)
>>>>> are a dying race. Most people do not even know it exists.
>>>>>
>>>>
>>>> Usenet was just one example of an existing forum, if you don't like
>>>> usenet
>>> What in the sentence 'I love usenet' did you make think that I do not
>>> like it?
>>>
>>
>> I mean "like" in the context of where to post your script.
>
> I like to post it here, but it is not only about like, it is also
> about being effective. It is not opportune to answer a question in the
> LinkedIn bash group on usenet.
>

I didn't suggest doing that. I suggested posting your script on some
commonly used existing forum where it could help many people and
answering the question where it was asked but point them to the script
on that common forum rather than doing the opposite of posting your
script on LinkedIn and then posting messages on other forums directing
people to LinkedIn.

Ed.

Re: Wrote a bash script to create and add a swapfile

<tdjbtf$gpjv$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5674&group=comp.unix.shell#5674

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 13:26:55 -0500
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <tdjbtf$gpjv$2@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
<87wnb697uy.fsf@munus.decebal.nl> <tdj6k8$g6be$1@dont-email.me>
<87zgg27op0.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 18:26:55 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="550527"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iEWx9FPfD9fR3MQjPOsgl"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:ZarD7IYPGI4MmdzUmohj9KzNxMs=
In-Reply-To: <87zgg27op0.fsf@munus.decebal.nl>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 220817-6, 8/17/2022), Outbound message
 by: Ed Morton - Wed, 17 Aug 2022 18:26 UTC

On 8/17/2022 12:41 PM, Cecil Westerhof wrote:
> Ed Morton <mortonspam@gmail.com> writes:
>
>> If you want your code to be compatible with ksh then, depending on
>> what
>
> No, I do not want that.
>
>
>> If you don't care about any of that then why not just make it the most
>> portable, `name ()`, especially since you're providing it as an example
>> for others to emulate and they might be trying to implement similar
>> functions in other shells.
>
> You would have preferred that everyone used BASICODE?
> https://en.wikipedia.org/wiki/BASICODE
>

I didn't suggest doing that. I suggested that when writing code that you
intend for many people to read and learn from where your target shell is
completely indifferent to multiple equivalent syntaxes, given a choice
of writing that code in a way that's portable to many shells or in a way
that's only portable to a small subset of shells, it's better to write
it in the way that's portable to many shells.

Ed.

Re: Meta re: the state of the economy and various other topics

<jm4thhF3h61U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5675&group=comp.unix.shell#5675

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: pjh@nanoworks.com (Percival John Hackworth)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: 17 Aug 2022 19:23:29 GMT
Lines: 61
Message-ID: <jm4thhF3h61U1@mid.individual.net>
References: <874jyccqbs.fsf@munus.decebal.nl> <tdj6la$g6be$2@dont-email.me> <874jya93sk.fsf@munus.decebal.nl> <tdjbku$gpjv$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=fixed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net gC/DT1dnhtAunvdyezZyVgETVvvo6jssm4WquEICrHpZ7OEcLj
Cancel-Lock: sha1:+jDWqXitk5I8zk/510o3UPhpm1M=
User-Agent: Usenapp for MacOS
X-Usenapp: v1.22/l - Full License
 by: Percival John Hackwo - Wed, 17 Aug 2022 19:23 UTC

On 17-Aug-2022 at 11:22:23AM PDT, "Ed Morton" <mortonspam@gmail.com> wrote:

> On 8/17/2022 12:29 PM, Cecil Westerhof wrote:
>> Ed Morton <mortonspam@gmail.com> writes:
>>
>>> On 8/17/2022 11:39 AM, Cecil Westerhof wrote:
>>>> Ed Morton <mortonspam@gmail.com> writes:
>>>>
>>>>> On 8/17/2022 10:48 AM, Cecil Westerhof wrote:
>>>>>> Ed Morton <mortonspam@gmail.com> writes:
>>>>>>
>>>>>>> On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
>>>>>>> <snip>
>>>>>>>> I created a bash group on LinkedIn and there was a question about how
>>>>>>>> to learn to program in bash. So I wrote a script and an article
>>
>> And this is why I posted it there and not here.
>>
>>
>>>>>>>> explaining the script with hopefully interesting tips for people how
>>>>>>>> to create their own scripts.
>>>>>>>> I just thought/hoped it could be interesting for people using this
>>>>>>>> newsgroup.
>>>>>>>
>>>>>>> Then I wish you had posted your script and article here and pointed
>>>>>>> people from LinkedIn here instead of doing it the other way around.
>>>>>> I do not think that will work. I love usenet, but we (users of usenet)
>>>>>> are a dying race. Most people do not even know it exists.
>>>>>>
>>>>>
>>>>> Usenet was just one example of an existing forum, if you don't like
>>>>> usenet
>>>> What in the sentence 'I love usenet' did you make think that I do not
>>>> like it?
>>>>
>>>
>>> I mean "like" in the context of where to post your script.
>>
>> I like to post it here, but it is not only about like, it is also
>> about being effective. It is not opportune to answer a question in the
>> LinkedIn bash group on usenet.
>>
>
> I didn't suggest doing that. I suggested posting your script on some
> commonly used existing forum where it could help many people and
> answering the question where it was asked but point them to the script
> on that common forum rather than doing the opposite of posting your
> script on LinkedIn and then posting messages on other forums directing
> people to LinkedIn.
>
> Ed.

LinkEdIn is NOT the place I go to for technical help. The places already
mentioned here
are better for reaching more people, if that's truly what you want to do. But
your arguing
that point makes me think there's some alterior motive going on here. The more
you push
it the more that makes my point.
--
DeeDee, don't press that button! DeeDee! NO! Dee...

Re: Wrote a bash script to create and add a swapfile

<tdjihl$hgpf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5676&group=comp.unix.shell#5676

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 22:20:04 +0200
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <tdjihl$hgpf$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<tdiukl$f9b7$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 20:20:05 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f445db0acf488de7631dfeaa9f6cb4f8";
logging-data="574255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XATL6WPGJl2uJYVOeV/dp"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:AAxsBXPLe1bbm11NHPLrOxDzpWY=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <tdiukl$f9b7$2@dont-email.me>
 by: Janis Papanagnou - Wed, 17 Aug 2022 20:20 UTC

On 17.08.2022 16:40, Ed Morton wrote:
> On 8/17/2022 5:32 AM, Janis Papanagnou wrote:
>> On 16.08.2022 19:37, Cecil Westerhof wrote:
>
> <snip>
>
>> Since you want only the last line of the df output you can let awk do
>> that job; at the end of processing the last processed input line is
>> still available in the END section, a simple change
>>
>> df -BG $(dirname $1) |
>> awk 'END {print substr($4, 1, length($4) - 1)}'
>
> At the end of processing the last processed input line is not guaranteed
> to still available in the END section.
>
> The value of $4 or any other field or $0 is undefined (by POSIX)

Hi Ed, I'm not sure that matters here, given that bash is specified and
since the 'df -B' is also non-standard. So we can probably assume to be
safe in this context here with that implicit assumption. But, sure, for
other contexts that may be necessary, and it can be easy checked whether
it works or not in any environment.

> in the
> END section. In some awk variants it will be the $4 from the last record
> read as you want, but in others it'll be null, and in others still it
> could be anything else. To do what you show above portably in all awks
> would be:
>
> awk '{p=$4} END{print substr(p, 1, length(p) - 1)}'

You can still use the integer conversion to simplify the command

awk '{p=$4} END {print 0+p}'

Janis

>
> Regards,
>
> Ed.
>

Re: Wrote a bash script to create and add a swapfile

<20220817133248.758@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5677&group=comp.unix.shell#5677

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 20:35:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20220817133248.758@kylheku.com>
References: <874jyccqbs.fsf@munus.decebal.nl>
Injection-Date: Wed, 17 Aug 2022 20:35:51 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="77cf631fee23d93fddab7984d7c1d231";
logging-data="575182"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19j1LTb733C6aQxP4pigsNu2fJfduV2bj0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:mWwTRuGCirR1U9WWHI8kYm5yVCU=
 by: Kaz Kylheku - Wed, 17 Aug 2022 20:35 UTC

On 2022-08-16, Cecil Westerhof <Cecil@decebal.nl> wrote:
> For people who know Bash, but like to learn write (better) scripts I
> wrote an article about a script I wrote to create and add a swapfile:
> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>
> You can get the script here:
> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh

A script like this is a good idea.

The last time I needed to make a swap file on Linux was at least fifteen
years ago. I can spew the commands to do it in my sleep: dd to create
the file, then mkswap and swapon.

Yet, I never "chmod 0600" on the file; and root's umask is often 022,
leaving files readable to others.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Wrote a bash script to create and add a swapfile

<tdjk29$hluv$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5678&group=comp.unix.shell#5678

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 22:46:01 +0200
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <tdjk29$hluv$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<87a682anfi.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 20:46:01 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f445db0acf488de7631dfeaa9f6cb4f8";
logging-data="579551"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gaBzYPRsUCw16J3DFeDYt"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:0zzsotwbAAbeTmajM2gKL6N/6FA=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <87a682anfi.fsf@munus.decebal.nl>
 by: Janis Papanagnou - Wed, 17 Aug 2022 20:46 UTC

On 17.08.2022 17:40, Cecil Westerhof wrote:
> Janis Papanagnou <janis_papanagnou@hotmail.com> writes:
>> On 16.08.2022 19:37, Cecil Westerhof wrote:
>>> Cecil Westerhof <Cecil@decebal.nl> writes:
>>>
>
>>> function getFreeGB {
>>> df -BG $(dirname $1) | \
>>> tail -n 1 | \
>>> awk '{print substr($4, 1, length($4) - 1)}'
>>> }
>>
>> In scripting the backslashes as a line continuation are a bad concept
>> since you don't see whether there's whitespace characters (other than
>> the newline character) there. Specifically a final pipe symbol doesn't
>> need any explicit textual line continuation so it can be anyway just
>> omitted.
>
> I know that you have to be careful that the backslash is the last
> character on the line, but I find it important that lines (if
> possible) are less as 80 characters.
> I did not know that the final pipe symbol does not need an explicit
> context. That is going to make my live easier.

That's often (always?) possible in cases where an incomplete syntactical
expression is given; works, for example, also with conditional commands

[[ -f "$f" ]] &&
rm "$f"

Long pipelines and conditional commands are the most common cases [in
my scripts] where long lines often appear and should be folded.

>
>> Below I am wondering why you are not consistently using braces when
>> expanding variables; we see ${0} and $2, and we see ${_gbFree} and
>> $_gb. I think this is confusing for folks that are learning shell -
>> as I understood that this was the (or one) intention of your post.
>> Whatever you prefer, but mixing is not a good thing as a paragon.
>
> Oops, that I used ${0} was certainly wrong. :'-(

Erm, ${0} is not "wrong", I just meant that it's inconsistently used.

>
> Let me explain. In the past people where really annoyed by me using
> braces. "It is not necessary." But there are some cases where they are
> important. That is why I decided that when the length of a name is not
> more as 4 characters long I will not use braces and otherwise I will.
> But I should explain that.

In my scripts I use generally braces, to be consistent, and to make
it work in any of the cases where it's necessary. Examples for that;
composition of variable name with alphanumeric suffix: ${var}_suffix,
or with positional parameters for numbers greater than 9: ${12}, or
to be syntactically consistent with the complex string operations,
e.g. ${var/x/y}, ${#str}, ${a[@]}, etc.

>
>> Since you're using a modern shell like bash (and obviously don't
>> restrict to POSIX)
>
> I am a bit on the fence with that. In a way I like to confirm to
> POSIX. But not rigorously. For example I use long options, but
> mentions what the corresponding short ones are. Handy for people that
> have a POSIX compliant awk.

First please note that my comment here was just an _observation_,
not a valuation or criticism. From the observation I derived that
my further suggestions needed not be POSIX'ly portable.

For me, POSIX is far too restricted to be happily using it. (Unless
explicitly necessary for portability) I restrict to it mainly only
if my deviations from POSIX are insignificant and I can omit them
without loss. On the other hand - note I'm using ksh - I often use
the ksh extensions if they are also supported by bash and zsh, and
I use the major extensions of ksh that are not available in bash
if unavoidable (e.g. built-in floating point arithmetic [without
falling back to external processes], or complex things like the
type system, discipline functions, and similar).

Janis

Re: Wrote a bash script to create and add a swapfile

<tdjkd7$hluv$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5679&group=comp.unix.shell#5679

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 22:51:51 +0200
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <tdjkd7$hluv$2@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
<20220817170126.7dcb0795@nx-74205> <87k07695mp.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 20:51:51 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f445db0acf488de7631dfeaa9f6cb4f8";
logging-data="579551"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mUvCSYFC9VMwEfg2AKChc"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:2bHT2HUnLRI+KwL8zauRZy56yk0=
In-Reply-To: <87k07695mp.fsf@munus.decebal.nl>
 by: Janis Papanagnou - Wed, 17 Aug 2022 20:51 UTC

On 17.08.2022 18:50, Cecil Westerhof wrote:
> Aragorn <thorongil@telenet.be> writes:
>
>> I agree with that, and I myself always write my scripts in the most
>> portable way, but the OP has very clearly indicated that it is a bash
>> script, and that it's specifically intended for use in GNU/Linux, where
>> GNU bash is still the main shell.
>
> I have heard of people that used my bash library on a non Linux
> system, but it is a very small minority. I myself work only with
> Linux.

You have specified an interpreter as first line #!/usr/bin/env bash
so I assume it's an executable - or at least that's a documentation
for users to not let it run under different shells. - That's fine.

Janis

Re: Wrote a bash script to create and add a swapfile

<87o7wi7drp.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5680&group=comp.unix.shell#5680

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 23:37:14 +0200
Organization: Decebal Computing
Lines: 42
Message-ID: <87o7wi7drp.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<87a682anfi.fsf@munus.decebal.nl> <tdjk29$hluv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="607832"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18s8sUQzM+I3xO+s+vR8tIVoN7LpeHt0Y8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:sTsHSn4XQLVPTQOlX1z53n1upFE=
sha1:TtGUwnJ9mznzuy2R30oxGoCRgz4=
 by: Cecil Westerhof - Wed, 17 Aug 2022 21:37 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:

> On 17.08.2022 17:40, Cecil Westerhof wrote:
>> Oops, that I used ${0} was certainly wrong. :'-(
>
> Erm, ${0} is not "wrong", I just meant that it's inconsistently used.

Wrong in the sense that I only use braces when a variable name is
longer as four characters. ;-)

>> Let me explain. In the past people where really annoyed by me using
>> braces. "It is not necessary." But there are some cases where they are
>> important. That is why I decided that when the length of a name is not
>> more as 4 characters long I will not use braces and otherwise I will.
>> But I should explain that.
>
> In my scripts I use generally braces, to be consistent, and to make
> it work in any of the cases where it's necessary. Examples for that;
> composition of variable name with alphanumeric suffix: ${var}_suffix,
> or with positional parameters for numbers greater than 9: ${12}, or
> to be syntactically consistent with the complex string operations,
> e.g. ${var/x/y}, ${#str}, ${a[@]}, etc.

Well, maybe I can change my ways again. But honestly I find ${0}
looking a bit weird. That is why I find it so strange I used it.

> without loss. On the other hand - note I'm using ksh - I often use
> the ksh extensions if they are also supported by bash and zsh, and
> I use the major extensions of ksh that are not available in bash
> if unavoidable (e.g. built-in floating point arithmetic [without
> falling back to external processes], or complex things like the
> type system, discipline functions, and similar).

Yes, floating point arithmetic is something I sometimes miss very
much.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<87k0767dlz.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5681&group=comp.unix.shell#5681

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 23:40:40 +0200
Organization: Decebal Computing
Lines: 27
Message-ID: <87k0767dlz.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
<20220817170126.7dcb0795@nx-74205> <87k07695mp.fsf@munus.decebal.nl>
<tdjkd7$hluv$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="607832"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ho6SGj+UHSp7cQPOizv1od0K7dYHMzCA="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:70j/n3STMb0JfQFzgKmdoLQ2L3s=
sha1:z2+sR9EPprvqsEmIWcR3X/Yh510=
 by: Cecil Westerhof - Wed, 17 Aug 2022 21:40 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:

> On 17.08.2022 18:50, Cecil Westerhof wrote:
>> Aragorn <thorongil@telenet.be> writes:
>>
>>> I agree with that, and I myself always write my scripts in the most
>>> portable way, but the OP has very clearly indicated that it is a bash
>>> script, and that it's specifically intended for use in GNU/Linux, where
>>> GNU bash is still the main shell.
>>
>> I have heard of people that used my bash library on a non Linux
>> system, but it is a very small minority. I myself work only with
>> Linux.
>
> You have specified an interpreter as first line #!/usr/bin/env bash
> so I assume it's an executable - or at least that's a documentation
> for users to not let it run under different shells. - That's fine.

I sometimes got flack for that also. "That is overkill." But bash can
(or at least could) be on different places. While /usr/bin/env should
exist on all systems. (Could be through a link.) And in this way my
bash scripts should run on all systems where bash is installed.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<87fshu7d2d.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5682&group=comp.unix.shell#5682

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 23:52:26 +0200
Organization: Decebal Computing
Lines: 51
Message-ID: <87fshu7d2d.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl> <20220817133248.758@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="615319"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HiGUeH5NWz58zMggrXM72enzu/zTWDlA="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:YtmvCWqD998J6PHyFnALeemYkCA=
sha1:hZPniobKCP+s8Ka13VzkX0daCq8=
 by: Cecil Westerhof - Wed, 17 Aug 2022 21:52 UTC

Kaz Kylheku <480-992-1380@kylheku.com> writes:

> On 2022-08-16, Cecil Westerhof <Cecil@decebal.nl> wrote:
>> For people who know Bash, but like to learn write (better) scripts I
>> wrote an article about a script I wrote to create and add a swapfile:
>> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>>
>> You can get the script here:
>> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh
>
> A script like this is a good idea.

I thought so. To use and as an exercise.
And an added benefit is that I learned something along the way.

One of the things I learned is that readonly eats your exit code. That
is why I now use:
declare -i _gbFree
_gbFree=$(getFreeGB "${_swapFile}")
readonly _gbFree

I find it to verbose, but when it is needed to circumvent a bug …

> The last time I needed to make a swap file on Linux was at least fifteen
> years ago. I can spew the commands to do it in my sleep: dd to create
> the file, then mkswap and swapon.

I almost never have done it. I had to look it up. That made me think
it would be nice to have it. This combined with a question about how
to become more proficient in bash made me write it.

> Yet, I never "chmod 0600" on the file; and root's umask is often 022,
> leaving files readable to others.

With all the bad possibilities.

I was told that the group should be also disk. (Did not see that on
the internet. Maybe should do a search on that.) But that is the nice
thing about a script: when you learn of extra restrictions it is very
easy to apply them and you have not to be afraid that you will forget
them.

As they say: things you do seldom you should automate.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<tdk062$kmf4$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5684&group=comp.unix.shell#5684

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Thu, 18 Aug 2022 02:12:49 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <tdk062$kmf4$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<87a682anfi.fsf@munus.decebal.nl> <tdjk29$hluv$1@dont-email.me>
<87o7wi7drp.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Aug 2022 00:12:50 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="aeb57e2c660c4b6ded80bdf82c446bd5";
logging-data="678372"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/G6UehpZ7AZDOMM/ChOJ0V"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:O9T+e2HV5et3TxCtozoO5I2xHjo=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <87o7wi7drp.fsf@munus.decebal.nl>
 by: Janis Papanagnou - Thu, 18 Aug 2022 00:12 UTC

On 17.08.2022 23:37, Cecil Westerhof wrote:
>
> Well, maybe I can change my ways again. But honestly I find ${0}
> looking a bit weird. That is why I find it so strange I used it.

Frankly, I don't use ${1} etc., I use $1. (In case of $0 it's often
only used in context of ${0##*/}, i.e. to strip the path component.)
Why so? Because it's rare in practice that you need hard access to
so many positional parameters; design-wise there's usually better
options to achieve that. One sometimes used special case is access
to the last element where [the classical way] you need braces; e.g.
in expressions like eval last=\${$#} but then there's also the
newer (non-standard) syntax ${@: -1:1} available in some shells.

Janis

Re: Wrote a bash script to create and add a swapfile

<tdkvh2$ura8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5685&group=comp.unix.shell#5685

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Thu, 18 Aug 2022 11:07:46 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <tdkvh2$ura8$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<87a682anfi.fsf@munus.decebal.nl> <tdjk29$hluv$1@dont-email.me>
<87o7wi7drp.fsf@munus.decebal.nl> <tdk062$kmf4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Aug 2022 09:07:47 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="aeb57e2c660c4b6ded80bdf82c446bd5";
logging-data="1011016"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qC2lVp9cZMIeFgC2EtPjg"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:f5WRoHh1vc4oXQE3CmMkGUzmORs=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <tdk062$kmf4$1@dont-email.me>
 by: Janis Papanagnou - Thu, 18 Aug 2022 09:07 UTC

On 18.08.2022 02:12, Janis Papanagnou wrote:
> On 17.08.2022 23:37, Cecil Westerhof wrote:
>>
>> Well, maybe I can change my ways again. But honestly I find ${0}
>> looking a bit weird. That is why I find it so strange I used it.
>
> Frankly, I don't use ${1} etc., I use $1. [...]

As it occurred to me, this is not quite true. I have the habit to
map the meaningless numbered parameters to names at the top of
the script (same with function parameters), thereby also forcing
a test of mandatory parameters, as in

filename=${1:?} amount=${2:?} reverse=${3}

and write the optional parameters (for consistency) also with
braces.

The case that I use $1 without braces is thus rare and mostly
done only in small ad hoc test scripts or ad hoc commands.

An exception is "$@", $?, etc.

Janis

Re: Wrote a bash script to create and add a swapfile

<bpo1ti-61f.ln1@ID-313840.user.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5686&group=comp.unix.shell#5686

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geoff@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Thu, 18 Aug 2022 13:43:55 +0100
Lines: 10
Message-ID: <bpo1ti-61f.ln1@ID-313840.user.individual.net>
References: <874jyccqbs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<tdiukl$f9b7$2@dont-email.me> <871qteamv5.fsf@munus.decebal.nl>
<tdj3kg$9is2$1@news.xmission.com>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net y/aimH9VtiAhG+6FtDpFygIbU5m7ChMqRL52mXyqLK6uCyk7q2
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:TGMldZ1PiPd50Z4h6ZMuiiHyCLo=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Thu, 18 Aug 2022 12:43 UTC

Kenny McCormack wrote:

> Until fairly recently, using plain "awk" under Solaris got you a very old,
> essentially non-functional version of AWK.

Only if you didn't set your PATH appropriately. (I.e. didn't put
/usr/xpg4/bin before /bin or /usr/bin).

--
Geoff Clare <netnews@gclare.org.uk>

Re: Wrote a bash script to create and add a swapfile

<sm0r11cbdov.fsf@lakka.kapsi.fi>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5692&group=comp.unix.shell#5692

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: as@sci.fi (Anssi Saari)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Fri, 19 Aug 2022 15:49:52 +0300
Organization: An impatient and LOUD arachnid
Lines: 15
Message-ID: <sm0r11cbdov.fsf@lakka.kapsi.fi>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<tdiukl$f9b7$2@dont-email.me> <871qteamv5.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="6975d62b9d586cc49e09608c59021d67";
logging-data="1569438"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18H5kfynMEB+3A93mZ+ygZV"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Cancel-Lock: sha1:RPpoQslDPDzsaRaC0nJ93mhTnLg=
sha1:ha05G3FIFDAHwITRBkhzs9Vc5LY=
 by: Anssi Saari - Fri, 19 Aug 2022 12:49 UTC

Cecil Westerhof <Cecil@decebal.nl> writes:

>> awk '{p=$4} END{print substr(p, 1, length(p) - 1)}'
>
> For me it works, but I should implement something like this then.

Why not just use stat to get the amount of free space on the file
system? Seems more reasonable than parsing df output. Although stat
seems to give free space in blocks so one needs to do extra work to find
out the block size too and then a bit of arithmetic to get
gigabytes. But it might avoid the issue on btrfs mentioned before.

Also I wonder if a pagefile actually needs to prewritten out like that
with dd or if creating a sparse file with truncate would be enough.

Re: Wrote a bash script to create and add a swapfile

<tdo39o$1fv57$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5693&group=comp.unix.shell#5693

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Fri, 19 Aug 2022 13:30:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <tdo39o$1fv57$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<tdiukl$f9b7$2@dont-email.me> <871qteamv5.fsf@munus.decebal.nl>
<sm0r11cbdov.fsf@lakka.kapsi.fi>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 19 Aug 2022 13:30:33 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="8db2e2fcbcb9af91acecfb8e48eebb64";
logging-data="1572007"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0W25J8p2Nt6ww0BDGUZR4ebNzBoVnTTQ="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:gcsObHygS6Dsu9qqhbNFNVvvZIo=
 by: Lew Pitcher - Fri, 19 Aug 2022 13:30 UTC

On Fri, 19 Aug 2022 15:49:52 +0300, Anssi Saari wrote:
[snip]

> Also I wonder if a pagefile actually needs to prewritten out like that
> with dd or if creating a sparse file with truncate would be enough.

From swapon(8):
"You should not use swapon on a file with holes.

The swap file implementation in the kernel expects to be able to write
to the file directly, without the assistance of the filesystem. This
is a problem on preallocated files (e.g. fallocate(1)) on filesystems
like XFS or ext4, and on copy-on-write filesystems like btrfs. It is
recommended to use dd(1) and /dev/zero to avoid holes on XFS and ext4."

HTH
--
Lew Pitcher
"In Skills, We Trust"


devel / comp.unix.shell / Re: Wrote a bash script to create and add a swapfile

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor