LinuxQuestions.org
Review your favorite Linux distribution.
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 09-28-2020, 02:03 PM   #1
dminican_slax
LQ Newbie
 
Registered: Aug 2020
Posts: 8

Rep: Reputation: 0
Any suggestion on exercises or projects?


I am starting to learn to play around with scripts so I want to know if any of you know of exercises, projects or a way I can practice shell scripting? I know I could just create one or two scripts using things I already but I kinda don't have any ideas what to do so I can use what I learned besides the old boring 'hello world's programs.








thanks in advance
 
Old 09-28-2020, 02:15 PM   #2
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 966

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738

Have you put words like "shell script practice exercises" into a search engine yet?

 
2 members found this post helpful.
Old 09-28-2020, 02:17 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,513
Blog Entries: 11

Rep: Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473
I doubt anyone could answer this in any way better than you can answer it yourself.

If you are programming in any language without some goal already in mind then you are kind of lost before you begin, in my opinion.

What problem would you like to solve, or what would be useful to you, that could be done with a computer? Make a list and pick a starting point.

As far as shell scripting, assuming that is what you mean by "scripting", one of the most rewarding exercises I ever undertook was to work my way through the bash man page trying to understand every topic and write a simple script to illustrate for myself fully how each feature actually works, and doesn't work, and explore how to usefully apply them. If you have no other goal, pick a language and open the man page or find a book, then see where it leads...

Good luck!
 
Old 09-28-2020, 02:34 PM   #4
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,259

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by dminican_slax View Post
I am starting to learn to play around with scripts so I want to know if any of you know of exercises, projects or a way I can practice shell scripting? I know I could just create one or two scripts using things I already but I kinda don't have any ideas what to do so I can use what I learned besides the old boring 'hello world's programs.
What do you tend to use your computer for? Why not begin learning about scripting by writing scripts to incorporate the commands you've been issuing "by hand" to automate some of the tasks you've been doing? (Some people say that it's not "necessity" but "laziness" that's the real Mother of Invention.)
 
Old 09-28-2020, 03:49 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,148
Blog Entries: 13

Rep: Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221
Search backwards in this Programming forum, and also Newbie, and probably Linux-General and Software.

I searched a bit and finally did find the threads I was thinking about, credit to teckk, here's a search of threads created by them, https://www.linuxquestions.org/quest...rchid=10946912 excuse me for identifying them in particular, but I recall they created some "exercise threads for bash" and you can find those in there. Plus there are quite a few bash questions you'll see. Reading those and also viewing the expertise I've seen from various members here is great stuff, if you're really interested in studying the topic.

At least one member I know of, when there's a bash question, some of which they've also created on their own, they just post scripts and improve them. As I say, you can see the evidence of who is good at bash language by back-tracking in this very forum. I'm sure if you post something where you're serious about it, you'll get lots of help, if not people doing it for you, but also very much working with you.

Didn't work here, probably because you didn't write BASH in your thread title, but roll down and you'll see "similar threads". Same thing, start a new thread and the engine will show you similar threads it finds. Or just page through threads here, and also in Newbie, and use the browser CTRL-F to find the word bash.
 
Old 09-28-2020, 08:44 PM   #6
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 16,947
Blog Entries: 27

Rep: Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179Reputation: 5179
A web search for "bash script practice exercises" turns up many articles and tutorials, but I think rnturn's suggestion is a good one.

I'm hardly a scripting expert--well, hardly even a scripting novice--but the few successful ones I've written I was motivated to write because they accomplished things I wanted to accomplish to make my computing life easier.
 
Old 09-29-2020, 01:13 AM   #7
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 937

Rep: Reputation: 215Reputation: 215Reputation: 215
You could start by rewriting the sample code (in C) that you had posted earlier asking for suggestions for improvements.

AP
 
Old 10-01-2020, 10:33 AM   #8
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 7
Posts: 3,485

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Best first script to write is a backup script so you don't lose your scripts!
 
Old 10-03-2020, 09:48 PM   #9
dminican_slax
LQ Newbie
 
Registered: Aug 2020
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by boughtonp View Post
Have you put words like "shell script practice exercises" into a search engine yet?

Yes, I have put the words "shell script practice exercises" into a search engine, why are you asking?
 
Old 10-03-2020, 10:02 PM   #10
dminican_slax
LQ Newbie
 
Registered: Aug 2020
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by astrogeek View Post
I doubt anyone could answer this in any way better than you can answer it yourself.

If you are programming in any language without some goal already in mind then you are kind of lost before you begin, in my opinion.

What problem would you like to solve, or what would be useful to you, that could be done with a computer? Make a list and pick a starting point.

As far as shell scripting, assuming that is what you mean by "scripting", one of the most rewarding exercises I ever undertook was to work my way through the bash man page trying to understand every topic and write a simple script to illustrate for myself fully how each feature actually works, and doesn't work, and explore how to usefully apply them. If you have no other goal, pick a language and open the man page or find a book, then see where it leads...

Good luck!
I took an entry level algorithms and java course in a government sponsored technical institution, there they taught us using a hands-on kind of approach so we had a list of exercises/problems we had to solve for every topic, so if the topic was for or while loops we were assigned something like 30 exercises so we could practice at home, I have several books on programming already but the way they explain things is based around a topic and focus on only one code and then we modify said code like once or twice.

What I want is exercises or real life problem-solving practice, not a man explanation if I wanted that I wouldn't be here asking for something different.
 
Old 10-03-2020, 10:06 PM   #11
dminican_slax
LQ Newbie
 
Registered: Aug 2020
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rtmistler View Post
Search backwards in this Programming forum, and also Newbie, and probably Linux-General and Software.

I searched a bit and finally did find the threads I was thinking about, credit to teckk, here's a search of threads created by them, https://www.linuxquestions.org/quest...rchid=10946912 excuse me for identifying them in particular, but I recall they created some "exercise threads for bash" and you can find those in there. Plus there are quite a few bash questions you'll see. Reading those and also viewing the expertise I've seen from various members here is great stuff, if you're really interested in studying the topic.

At least one member I know of, when there's a bash question, some of which they've also created on their own, they just post scripts and improve them. As I say, you can see the evidence of who is good at bash language by back-tracking in this very forum. I'm sure if you post something where you're serious about it, you'll get lots of help, if not people doing it for you, but also very much working with you.

Didn't work here, probably because you didn't write BASH in your thread title, but roll down and you'll see "similar threads". Same thing, start a new thread and the engine will show you similar threads it finds. Or just page through threads here, and also in Newbie, and use the browser CTRL-F to find the word bash.

Thanks for your suggestion man really appreciate it.
 
Old 10-03-2020, 10:10 PM   #12
dminican_slax
LQ Newbie
 
Registered: Aug 2020
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rnturn View Post
What do you tend to use your computer for? Why not begin learning about scripting by writing scripts to incorporate the commands you've been issuing "by hand" to automate some of the tasks you've been doing? (Some people say that it's not "necessity" but "laziness" that's the real Mother of Invention.)
I've done some of that already, I thought you guys could have a better or a more in depth knowledge about this.
 
Old 10-06-2020, 11:52 AM   #13
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,259

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by dminican_slax View Post
I've done some of that already, I thought you guys could have a better or a more in depth knowledge about this.
I bring up the "what do you use your computer for" out of experience. I learned C by translating a satellite simulation from FORTRAN to C because I wanted to learn C and coding "Hello, world!" or Fibonacci and fizz-buzz sequences just didn't do it for me. (This exercise was something learned that resulted in a consulting gig many years ago converting FORTRAN->C for a company that you've almost certainly heard of). Lately, my personal project had been been ripping close to 2000 CDs to FLAC files (yeah, I'm kind of a music fan). I guarantee you I'm not doing that by hand---it's evolved from a collection of shell scripts to a smaller collection of Python (and one Perl... for now) scripts. You run into all sorts of problems when automating tasks so you'll learn more than a little something about troubleshooting along the way.

Bottom line: Only you know what floats your computing boat.

Cheers...
 
Old 10-06-2020, 02:04 PM   #14
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,148
Blog Entries: 13

Rep: Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221Reputation: 4221
Quote:
Originally Posted by dminican_slax View Post
Yes, I have put the words "shell script practice exercises" into a search engine, why are you asking?
No offense I'm sure, but your original question left out if you did this. Perhaps not trying to imply that someone was being negative towards you, instead consider their suggestion at face value, which is a web search would turn up a lot of hits. If you had searched, then sharing insight into how that effort didn't yield what you were looking for would have been helpful to know at the start.
Quote:
Originally Posted by dminican_slax View Post
I've done some of that already, I thought you guys could have a better or a more in depth knowledge about this.
Well you quoted and thanked me for my advice, which says very clearly that there are TONS of users on LQ who are very good with bash scripts and looking in thread histories will reveal that.

Or better yet, write a small script, post it in a thread question and ask for critiques or assistance to accomplish some things which you had not been able to quite get right. Guarantee that a lot of people may even re-write your script and post that back. But challenging people as to why they ask details or implying that members aren't as sharp as you expected, probably is not the best tact. But, as you will, enjoy your experiments with bash scripting.
 
Old 10-13-2020, 10:47 PM   #15
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 232Reputation: 232Reputation: 232
I know I'm late to the party, but if the OP is still looking for shell scripting exercises here are a couple of "real world" examples from my ~/bin directory and the concepts involved.

Fuzzy Helper
Using a combination of find and a fuzzy finder such as fzf or fzy, list all files/directories up to a maximum depth, and prompt the user to choose a file. After a file (or directory) is chosen, decide what action to take based on the MIME type, e.g. if the file is a compressed file, decompress the file and pipe the output to $PAGER.

Concepts
Using the find command to find files. Look at the man page to figure out how to filter out hidden files and directories.
Piping output from one command to another and saving the result.
Controlling the flow of a program.

Music Player Status
I like testing out different CLI music players, such as cmus. I wanted to be able to get information about the current song that I could then display either in my terminal or on my status bar, so I wrote a script that can query that information for various players.

Concepts
The same concepts as above.
Communicating with another program using sockets.
Text manipulation: How would you extract certain bits of data from a string?
Functions
Loops
Redirecting output

If you are looking for learning resources, I would recommend the Bash Beginners Guide and the Advanced Bash Scripting Guide. Don't forget to refer to the man pages for any programs you come across.

Last edited by individual; 10-13-2020 at 10:48 PM. Reason: Punctuation fixes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Any advance C++ exercises. Nabeel Programming 2 12-11-2013 03:17 AM
new to linux, exhaustive command line exercises rajneesh_mangla Linux - Software 2 02-08-2006 03:56 PM
trying out exercises from Kernighan and Ritchie dvm Programming 2 11-22-2004 08:07 PM
Learning Exercises - Where can I find them? BenChase Slackware 3 12-15-2003 08:45 AM
exercises for learning c... Sky Programming 25 07-18-2002 02:33 AM

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

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