Question on bash command line

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Question on bash command line
# 1  
Old 08-01-2018
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 7013 and not 2013. So I move the cursor to the left and keep it on top of 2 (of 2013) and I want to replace 2 with 7. How can I do that ?

$ echo hello world 2013

This question is not about replacing characters within vi/vim/emacs

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 . I tried googling and I couldn't find anything on this. Hence posting it here.

Oracle Performance Tuning - Loading Data - 03 Using manual parallelism and changing initrans - YouTube

Last edited by kraljic; 08-01-2018 at 11:13 AM..
# 2  
Old 08-01-2018
To use vi to edit your command line or navigate the

command history: set -o vi

To bring the previous command: k

To navigate by words on a command line: b

man vi for the options.
# 3  
Old 08-01-2018
Ok. After I set set -o vi

how can I replace 2 which under the cursor with 7 ?
# 4  
Old 08-01-2018
By issuing 's' over a character and typing a new number, followed by escape.

Regards
Peasant.
# 5  
Old 08-01-2018
Surely to replace just the character under the cursor in vi mode you type 'r' followed by the new character.

Personally, I prefer the emacs mode. It is more intuitive (unlike emacs!)

In emacs mode, to change the character under the cursor, you use Ctrl-D to delete the character and type the new one.

Andrew
# 6  
Old 08-01-2018
Quote:
Originally Posted by apmcd47
Surely to replace just the character under the cursor in vi mode you type 'r' followed by the new character.

Personally, I prefer the emacs mode. It is more intuitive (unlike emacs!)

In emacs mode, to change the character under the cursor, you use Ctrl-D to delete the character and type the new one.

Andrew
"I prefer editors one can use without being a professional pianist." [(c) bakunin @unix.com] Smilie
# 7  
Old 08-01-2018
You move to the 0 , hit <Del Left> or <Ctrl-H>, and type 7 .



If you want to replace the char you're on, you'll have to switch bash's readline library to "overwrite-mode". By default, this command is unbound, so you need to bind it, e.g.:
Code:
bind "\C-y":overwrite-mode

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

Cp command works on command line but not in bash

The below command moves all the .vcf files into the directory. cp /home/cmccabe/Desktop/test/vcf/overall/stats/*.vcf /home/cmccabe/Desktop/NGS/annovar When I use a bash wrapper the target.txt gets created but the text files do not get copied. All the paths are the same, but not sure why... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Question about Shebang line of Bash Script

Hello All, I was writing a Bash shell script that will be executed on both an AIX server (/usr/bin/ksh) and a SLES server (/bin/bash). The AIX server has Bash installed at "/usr/bin/bash", which is in a different dir then the SLES server. So basically I am writing the script on the SLES... (4 Replies)
Discussion started by: mrm5102
4 Replies

4. UNIX for Dummies Questions & Answers

NEWB Question - BASH COMMAND RESULT for ${0##*/}

This should be extremely simple and someone will probably answer it in .5 seconds. I need to know what: VARIABLE=${0##*/} does? I do not have a shell handy to just try it in. I am reading through some scripts and need to understand this line. Any help is appreciated. Many thanks! -... (3 Replies)
Discussion started by: chrisgoetz
3 Replies

5. Shell Programming and Scripting

Bash - Loading a command's output line by line into an array

I have been trying this a lot of different ways and haven't found too much online. Here's what I've got so far: j=0 declare -a first zero=(`cat $tmpfile`) for i in "${zero}" do command $i >> "${first}" ... (4 Replies)
Discussion started by: Azrael
4 Replies

6. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

7. AIX

Typing "bash" at the command line spawns two bash processes

Server: IBM p770 OS: AIX 6.1 TL5 SP1 When one of our develoeprs types "bash" on the command line to switch shells, it hangs. For some reason, two bash processes are created....the first bash process spawns a second bash process in the same console, causing a hang. Anyone have any idea what... (2 Replies)
Discussion started by: wjssj
2 Replies

8. Shell Programming and Scripting

BASH Command Line Typo -- Can't Get Out

Hi Sorry to post a bit of an "I'm an idiot" post, but I did a typing error and typed "ls 'l" instead of "ls -l". This seems to have made me enter some sort of mode or other that I can't seem to be able to get out of. The new line prompt is > (if that helps). Sorry for posting such a... (1 Reply)
Discussion started by: Viola
1 Replies

9. UNIX for Dummies Questions & Answers

editing bash command line with vi

Is there a way using bash that I can edit a command line using vi. I.e. if I have a long command line and I want to edit it.....by typing vi and then having the command open in an editing window.... I beleive this can be done in k shell by pressing v....however can find out how this can be... (3 Replies)
Discussion started by: peter.herlihy
3 Replies
Login or Register to Ask a Question