LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-03-2018, 05:50 AM   #1
kraljic
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Rep: Reputation: Disabled
Question on bash command line


OS : RHEL / Oracle Linux 6.8

In bash shell, how can I replace a character under the cursor with another character ?

In the below example , after I typed the following line, I realized that I meant 7018 and not 2018. So I move the cursor to the left and keep it on top of 2 (of 2018) and I want to replace 2 with 7. How can I do that ?
$ echo hello 2018
This question is not about replacing characters in a text file using vi/vim/emacs editors.

A video example (for more clarity)
In the below video, how is this guy changing 2010 to 2011 instantly ? He also changes 2011 to 2012 , ... etc

https://youtu.be/ch5g_veylAM?t=361
Attached Thumbnails
Click image for larger version

Name:	DD.png
Views:	19
Size:	1.7 KB
ID:	28321  
 
Old 08-03-2018, 06:48 AM   #2
lougavulin
Member
 
Registered: Jul 2018
Distribution: Slackware,x86_64,current
Posts: 280

Rep: Reputation: 100Reputation: 100
There is at least one way to do this :
$ set -o vi

$ echo hello 2018 (move cursor aver 2, type 'r' then'7'

But the VI mode is not "friendly" for a lot of people and change lot of things.
 
1 members found this post helpful.
Old 08-03-2018, 06:56 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,885
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by kraljic View Post
In bash shell, how can I replace a character under the cursor with another character ?

In the below example , after I typed the following line, I realized that I meant 7018 and not 2018. So I move the cursor to the left and keep it on top of 2 (of 2018) and I want to replace 2 with 7. How can I do that ?
Personally I go to the point just after the character, hit BACKSPACE to delete that character, and then type in my correction.


Meanwhile there is such as thing as insert mode which is natively on, in my terminal. Appears not to be in that video.
 
1 members found this post helpful.
Old 08-03-2018, 07:01 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by kraljic View Post
this is on macos, and while macos uses (its own version of) bash, it could also be a different shell.
it could be a function of that different shell, or a function of macos' terminal app, or one of the solutions proposed earlier.

there's also this: https://askubuntu.com/questions/6410...overwrite-mode
 
1 members found this post helpful.
Old 08-03-2018, 07:30 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,885
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Didn't really view that video in great enough detail. It is a good point, ondoho.

Meanwhile the behavior of overwrite is typically controlled by the INSERT key on my keyboard.

My default is that if I migrated back to part of my command and type something, it'll insert the new character, hence my description of what I normally do.

If I hit the INSERT key once, it now changes the mode to be overstrike, or overwrite and I see the exact same behavior from that video.

I've never preferred that mode. It doesn't work on all types of system terminals. But that's also what I meant when I used that term in my last post.
 
1 members found this post helpful.
Old 08-05-2018, 06:11 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,370

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
Quote:
Personally I go to the point just after the character, hit BACKSPACE to delete that character, and then type in my correction.
Yeah, in my experience, this nearly always works ie it's the default 'setting' unless someone has customised the login files and set it to OVERSTRIKE mode instead, but that is rare and easy to fix.
 
Old 08-05-2018, 07:29 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,763

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by kraljic View Post
OS : RHEL / Oracle Linux 6.8

In bash shell, how can I replace a character under the cursor with another character ?

In the below example , after I typed the following line, I realized that I meant 7018 and not 2018. So I move the cursor to the left and keep it on top of 2 (of 2018) and I want to replace 2 with 7. How can I do that ?
$ echo hello 2018
On my console, DEL followed by 7 would do that. Does that not work for you?
 
  


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
[SOLVED] How to run several bash commands put in bash command line BudiKusasi Linux - Newbie 8 01-23-2018 02:39 PM
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 12:05 AM
BASH shell question, variable sustitution $1... command line args mnemry Linux - Newbie 8 04-19-2011 04:40 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM
bash question: how to do "for a in b do..." on the command line Kropotkin Linux - Newbie 7 02-03-2006 08:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:51 AM.

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