LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2016, 07:53 AM   #1
webking
LQ Newbie
 
Registered: Feb 2014
Posts: 11

Rep: Reputation: Disabled
bash: replace word/s on screen with sed?


Hi all,

I need some help with bash commands to replace text live on the screen please. For example, currrently if I type "wget ?" I get "-bash: wget: command not found." What I would like to do is replace some text produce there. I want to replace the word "command" or any words before it prints out.

Is this possible? please advise.

Thanks a ton!
 
Old 05-12-2016, 08:05 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
I do not understand it at all. Do you want to catch the text entered and alter it before displayed?
 
Old 05-12-2016, 08:06 AM   #3
webking
LQ Newbie
 
Registered: Feb 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
Alter it before displayed please. Thanks.
 
Old 05-12-2016, 08:08 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
can you show some examples? What should be displayed during type? (pressing any keys?)
 
Old 05-12-2016, 09:47 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
I am a bit confused to ... you want to change the standard error messages displayed by bash??
 
Old 05-12-2016, 12:31 PM   #6
webking
LQ Newbie
 
Registered: Feb 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
Sorry for the confusion. Here's what I need to accomplish. For example:

Currently:
$ wget ? <ENTER>
-bash: wget: command not found

I want to see something like this after I hit the ENTER key.

$ wget ? <ENTER>
-bash: wget: WHATEVER not found

Basically after I hit enter, I want to hide or replace whatever text I wish in place of the original message. Please let me know if I m not clear again. Sorry.
 
Old 05-12-2016, 12:40 PM   #7
webking
LQ Newbie
 
Registered: Feb 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
you want to change the standard error messages displayed by bash??
Yes and add some extra. :O). Maybe I do not like the way it worded so I want a chance to replace some text. Thanks.
 
Old 05-12-2016, 01:01 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,727

Rep: Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919
By creating a shell function you can modify error messages a bit.

http://www.linuxjournal.com/magazine...proof?page=0,0
http://www.linuxplanet.com/linuxplan...orials/7025/1/
 
2 members found this post helpful.
Old 05-12-2016, 03:46 PM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
With Bash version 4, it seems you can write your own command not found handler function
Code:
command_not_found_handle () {
  echo "What is this thing?" >&2
  return 127
}

$ notfoundcommand
What is this thing?
Edit:
Quote:
Originally Posted by webking View Post
I want to see something like this after I hit the ENTER key.

$ wget ? <ENTER>
-bash: wget: WHATEVER not found
then the error message would be:
Code:
echo "-$0: $1: WHATEVER not found" >&2
Edit2:
I tend to like the trap handler method better (more possibilities), from the links given by michaelk

Last edited by keefaz; 05-12-2016 at 04:00 PM.
 
1 members found this post helpful.
  


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 replace exact word using sed santhosh.ananthula Linux - Desktop 4 01-27-2016 05:10 PM
sed: search for string, then match and replace the next occurance of a word nbritton Programming 4 01-21-2015 12:40 PM
[SOLVED] search and replace particular word with sed using variable roopakl Linux - Newbie 2 10-01-2012 11:08 AM
Trying to use sed to replace a number that is in a string with a word simpsonc Linux - Newbie 3 09-12-2010 07:55 PM
sed 1st word to replace all instances of ( donnied Programming 5 08-21-2008 06:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 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