<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bash on despatches</title><link>https://icle.es/tags/bash/</link><description>Recent content in Bash on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 20 Jun 2025 09:25:00 +0100</lastBuildDate><atom:link href="https://icle.es/tags/bash/index.xml" rel="self" type="application/rss+xml"/><item><title>How to fix terminal title after disconnecting from ssh</title><link>https://icle.es/2020/06/25/how-to-terminal-title-after-disconnecting-from-ssh/</link><pubDate>Thu, 25 Jun 2020 08:47:45 +0000</pubDate><guid>https://icle.es/2020/06/25/how-to-terminal-title-after-disconnecting-from-ssh/</guid><description>&lt;p>For some reason, ssh does not clean up after itself in terms of updating the
terminal title when you disconnect.&lt;/p>
&lt;p>Here is a simple solution, a combination of
&lt;a href="https://unix.stackexchange.com/a/341277/25975">https://unix.stackexchange.com/a/341277/25975&lt;/a> and
&lt;a href="https://unix.stackexchange.com/a/28520/25975">https://unix.stackexchange.com/a/28520/25975&lt;/a>&lt;/p>
&lt;p>Add the following functions into your &lt;code>~/.bashrc&lt;/code> It will push the current title
and icon into a stack and pop it afterwards.&lt;/p>
```bash
function ssh()
{
 # push current title and icon to stack
 echo -ne '\e[22t'
 # Execute ssh as expected
 /usr/bin/ssh "$@"
 # revert the window title after the ssh command
 echo -ne '\e[23t'
}
```
&lt;p>Restart bash / log out and back in, and it should work.&lt;/p></description><content:encoded><![CDATA[<p>For some reason, ssh does not clean up after itself in terms of updating the
terminal title when you disconnect.</p>
<p>Here is a simple solution, a combination of
<a href="https://unix.stackexchange.com/a/341277/25975">https://unix.stackexchange.com/a/341277/25975</a> and
<a href="https://unix.stackexchange.com/a/28520/25975">https://unix.stackexchange.com/a/28520/25975</a></p>
<p>Add the following functions into your <code>~/.bashrc</code> It will push the current title
and icon into a stack and pop it afterwards.</p>
```bash
function ssh()
{
    # push current title and icon to stack
    echo -ne '\e[22t'
    # Execute ssh as expected
    /usr/bin/ssh "$@"
    # revert the window title after the ssh command
    echo -ne '\e[23t'
}
```
<p>Restart bash / log out and back in, and it should work.</p>
<p>For security reasons, it is not possible to query the current title of the
terminal. However, with the following command, you can push the current one on
to a stack</p>
```bash
echo -ne '\e[22t'
```
<p>The title can then be set to anything, by ssh for example. You can then pop that
back from the stack using</p>
```bash
echo -ne '\e[23t'
```
]]></content:encoded></item><item><title>Looping from the bash commandline [1113]</title><link>https://icle.es/2011/12/20/looping-from-the-bask-commandline-1113/</link><pubDate>Tue, 20 Dec 2011 13:32:08 +0000</pubDate><guid>https://icle.es/2011/12/20/looping-from-the-bask-commandline-1113/</guid><description>&lt;p>I figured this out the other day from idle curiosity. There is occassionally the
need to have a never ending loop to be executed directly from the bash
commandline instead of writing a script.&lt;/p>
&lt;p>I used this to run sl (yes sl, not ls - try it - I love it) repeatedly.&lt;/p>
```
 $ while true; do ; done
```
&lt;p>for example&lt;/p>
```
 $ while true; do sl; done
```
&lt;p>Bear in mind that this loop is infinite and there is no way to cancel out of it
except to kill of the terminal.&lt;/p></description><content:encoded><![CDATA[<p>I figured this out the other day from idle curiosity. There is occassionally the
need to have a never ending loop to be executed directly from the bash
commandline instead of writing a script.</p>
<p>I used this to run sl (yes sl, not ls - try it - I love it) repeatedly.</p>
```
    $ while true; do ; done
```
<p>for example</p>
```
    $ while true; do sl; done
```
<p>Bear in mind that this loop is infinite and there is no way to cancel out of it
except to kill of the terminal.</p>
]]></content:encoded></item><item><title>Linux bulk search and replace</title><link>https://icle.es/2010/04/21/linux-bulk-search-and-replace/</link><pubDate>Wed, 21 Apr 2010 13:47:26 +0000</pubDate><guid>https://icle.es/2010/04/21/linux-bulk-search-and-replace/</guid><description>&lt;p>Doing a bulk search and replace across a set of files is actually surprisingly
easy. sed is the key. It has a flag - i that will modify the files passed to it
in-place.&lt;/p>
```bash
$ sed -e 's/TextToFind/Replacement/' -i file1 file2 file3
```
&lt;p>Tie this power with either grep &lt;code>-l&lt;/code>. (Thanks to Steve for pointing out a
mistake in the following, now corrected)&lt;/p>
```bash
$ grep -l TextToFind * |xargs sed -e 's/TextToFind/Replacement/' -i
```
&lt;p>or find&lt;/p></description><content:encoded><![CDATA[<p>Doing a bulk search and replace across a set of files is actually surprisingly
easy. sed is the key. It has a flag - i that will modify the files passed to it
in-place.</p>
```bash
$ sed -e 's/TextToFind/Replacement/' -i file1 file2 file3
```
<p>Tie this power with either grep <code>-l</code>. (Thanks to Steve for pointing out a
mistake in the following, now corrected)</p>
```bash
$ grep -l TextToFind * |xargs sed -e 's/TextToFind/Replacement/' -i
```
<p>or find</p>
```bash
$ find . -exec sed -e 's/TextToFind/Replacement' -i {} ;
```
<p>If there are multiple changes you want to make, just put them all into a file
and pass it in via the -f flag.</p>
<p>file: replacements.patterns</p>
```sed
s/TextToFind1/Replacement1/
s/TextToFind2/Replacement2/
s/TextToFind3/Replacement3/
```
<p>and the command, using find to iterate through all files in the current
directory and subdirectories.</p>
```bash
find . -exec sed -f replacements.patterns -i {} ;
```
<p>et voila - hope it helps.</p>
]]></content:encoded></item></channel></rss>