LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-05-2023, 10:08 AM   #1
finalturismo
Member
 
Registered: May 2019
Posts: 120

Rep: Reputation: Disabled
bashrc command line wrapper to install missing packages automatically


How can i wrap all commands in the bashrc file so that if it says command not found it will attempt to automatically install that missing command using apt-get ?
 
Old 02-05-2023, 11:56 AM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,138
Blog Entries: 6

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
Basic example:
Code:
#!/usr/bin/bash

read -p "Enter command: " com

if ! command -v "$com"; then
    echo "apt-get <something> "$com""
else
    echo "Command is found"
fi
 
Old 02-05-2023, 11:58 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,719

Rep: Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913Reputation: 5913
Ubuntu has a "wrapper" called command-not-found which provides a suggestion on how to install an application if not found. I know it is a python script and I have not delved into its inner workings but I know it uses a cache of programs and their associated packages. Hopefully, that should give you a base into how to add an automatic install function.

https://launchpad.net/ubuntu/+source/command-not-found

Last edited by michaelk; 02-05-2023 at 12:03 PM.
 
  


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
LXer: Use ChatGPT From The Command Line With This Wrapper LXer Syndicated Linux News 0 02-01-2023 11:32 PM
[SOLVED] Installing MaryTTS and Its Command-Line Wrapper Maryspeak julianvb Linux - Software 5 12-10-2015 12:49 AM
howto create GUI-graphical wrapper for command line program SaintDanBert Linux - Desktop 4 01-30-2011 08:24 PM
.bashrc / .bash_profile /etc/profile /etc/bashrc deadeyes Red Hat 2 02-13-2010 11:22 AM
Setting path: /etc/profile, /etc/bashrc or ~/.bashrc Swakoo Linux - General 1 08-07-2007 10:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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