C or Bash?

Forum rules
Before you post please read how to get help
Post Reply
StevenC21
Level 2
Level 2
Posts: 88
Joined: Mon Mar 19, 2018 11:02 pm

C or Bash?

Post by StevenC21 » Tue Apr 10, 2018 11:42 am

Which skill is more useful for a Linux user. Assume they are mutually exclusive, as in, you can only know and be proficient in one. Also, explain why; I want to increase my understanding. If this is the wrong forum please direct me to a good place for this.
"A computer is like air conditioning. It becomes useless when you open Windows."
- Linus Torvalds

User avatar
xenopeek
Level 24
Level 24
Posts: 22875
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: C or Bash?

Post by xenopeek » Tue Apr 10, 2018 12:29 pm

I depends entirely on the user in question. What are their goals or needs for learning a programming language.

For general users, not programmers, shell scripting (Bash) will likely be the more useful as the learning curve is much shorter. It gets them comfortable on the command line and lets them automate things with scripts. If they want to get into programming more complex things then obviously shell scripting will sooner rather than later be too limiting.

Want to get into kernel development or systems programming? Then C is the tool of choice. Though for systems programming there are a lot of other choices depending on needs and wants. Want to get into application programming? I'd opt for recommending Python 3 instead as that offers a much more useful standard library than C does. It gets a lot more done in a lot less lines of code.
Image

StevenC21
Level 2
Level 2
Posts: 88
Joined: Mon Mar 19, 2018 11:02 pm

Re: C or Bash?

Post by StevenC21 » Tue Apr 10, 2018 3:56 pm

When I said a Linux user, I suppose I should have been more specific. I did mean a standard user.
"A computer is like air conditioning. It becomes useless when you open Windows."
- Linus Torvalds

User avatar
MintBean
Level 9
Level 9
Posts: 2964
Joined: Fri Aug 07, 2015 6:54 am
Location: Blighty

Re: C or Bash?

Post by MintBean » Tue Apr 10, 2018 4:02 pm

It really depends what you're trying to achieve.

User avatar
karlchen
Level 19
Level 19
Posts: 9309
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: C or Bash?

Post by karlchen » Tue Apr 10, 2018 4:49 pm

Being a Linux (Mint) user does definitely not require any knowledge of the programming language C.
Knowing bash and knowing C are not mutually exclusive.
The scope of what you use them for are pretty different.
Image
Linux Mint 18.1 64-bit Cinnamon Desktop, Total Commander 9.21a 64-bit
Ubuntu 18.04.1 32-bit Mate Desktop, Total Commander 9.21a 32-bit
Windows? - 1 window in every room

StevenC21
Level 2
Level 2
Posts: 88
Joined: Mon Mar 19, 2018 11:02 pm

Re: C or Bash?

Post by StevenC21 » Tue Apr 10, 2018 5:25 pm

I know they aren't exclusive; I meant, in this hypothetical scenario, if you could only have one, which would you want?
"A computer is like air conditioning. It becomes useless when you open Windows."
- Linus Torvalds

User avatar
karlchen
Level 19
Level 19
Posts: 9309
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: C or Bash?

Post by karlchen » Tue Apr 10, 2018 5:34 pm

Bash. - You need a command interpreter. You do not need a programming language.
Image
Linux Mint 18.1 64-bit Cinnamon Desktop, Total Commander 9.21a 64-bit
Ubuntu 18.04.1 32-bit Mate Desktop, Total Commander 9.21a 32-bit
Windows? - 1 window in every room

User avatar
xenopeek
Level 24
Level 24
Posts: 22875
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: C or Bash?

Post by xenopeek » Tue Apr 10, 2018 5:45 pm

Did you intend this to be a kind of poll? We're taking this as a serious question from you because you posted here.
Image

StevenC21
Level 2
Level 2
Posts: 88
Joined: Mon Mar 19, 2018 11:02 pm

Re: C or Bash?

Post by StevenC21 » Tue Apr 10, 2018 9:52 pm

I meant it seriously. But anyways, are polls not acceptable here?
"A computer is like air conditioning. It becomes useless when you open Windows."
- Linus Torvalds

User avatar
xenopeek
Level 24
Level 24
Posts: 22875
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: C or Bash?

Post by xenopeek » Wed Apr 11, 2018 2:08 am

They would be more suitable in the chat forum.
Image

FreedomTruth
Level 4
Level 4
Posts: 417
Joined: Fri Sep 23, 2016 10:19 am

Re: C or Bash?

Post by FreedomTruth » Wed Apr 11, 2018 10:36 am

It really, really, really depends on what you are doing. bash is probably easier to use and quicker to get from pseudocode (concept) to actual working code, but it's certainly not always the best tool. Anecdotal case in point: I recently started working with csv-type data that has to be updated daily (there's a "main" file then smaller "update" files given each day); with my bash script this was taking 1-1.5 hrs to process each day. Granted, I'm not the best scripter and I'm sure my code could have been optimized to some extent; but after I rewrote it in c, the updating process now takes around 5 minutes. Working with large data sets, if speed is an issue, C is probably the way to go. For simple "do this command then do that command" type stuff, go with bash. I still have other bash scripts using the same data that I will probably not move to C because it works fine as-is, and doesn't seem worth it to rewrite the same thing.

If you could only use one, would you use a hammer or scissors?
If you abide in My word, you are My disciples indeed. And you shall know the truth, and the truth shall make you free... Most assuredly, I say to you, whoever commits sin is a slave of sin... Therefore if the Son makes you free, you shall be free indeed.

User avatar
Arch_Enemy
Level 6
Level 6
Posts: 1180
Joined: Tue Apr 26, 2016 3:28 pm

Re: C or Bash?

Post by Arch_Enemy » Wed Apr 11, 2018 10:48 am

StevenC21 wrote:
Tue Apr 10, 2018 3:56 pm
When I said a Linux user, I suppose I should have been more specific. I did mean a standard user.
Basically it depends what you are trying to accomplish.

C is more geared for putting together packages and can be used for writing small programs to accomplish functions.
Bash scripting, while very powerful in itself, is more geared for putting together strings of commands (this is oversimplified, it is pretty powerful). Think of BASH more along the lines of DOS .bat files.
I have travelled 35629424162.9 miles in my lifetime

One thing I would suggest, create a partition a ~28G partition as /. Partition the rest as /Home.
When the system fails, reinstall and use the exact same username and all your 'stuff' comes back to you.

User avatar
xenopeek
Level 24
Level 24
Posts: 22875
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: C or Bash?

Post by xenopeek » Wed Apr 11, 2018 10:52 am

Arch_Enemy wrote:
Wed Apr 11, 2018 10:48 am
DOS .bat files
This statement likely only means something to people older than 35 :)
Image

User avatar
Arch_Enemy
Level 6
Level 6
Posts: 1180
Joined: Tue Apr 26, 2016 3:28 pm

Re: C or Bash?

Post by Arch_Enemy » Wed Apr 11, 2018 10:59 am

xenopeek wrote:
Wed Apr 11, 2018 10:52 am
Arch_Enemy wrote:
Wed Apr 11, 2018 10:48 am
DOS .bat files
This statement likely only means something to people older than 35 :)
I fit that category quite aptly...
I have travelled 35629424162.9 miles in my lifetime

One thing I would suggest, create a partition a ~28G partition as /. Partition the rest as /Home.
When the system fails, reinstall and use the exact same username and all your 'stuff' comes back to you.

User avatar
Termy
Level 5
Level 5
Posts: 762
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: C or Bash?

Post by Termy » Mon Apr 16, 2018 7:49 pm

I'd absolutely opt for shell programming, and I did, and continue to do so; it might not give you nearly the flexibility of compiling languages like C, but it sure as heck makes life a lot easier than typing out thousands upon thousands of lines of code to get tasks done of which shell could make light work, which is especially useful in Linux and similar environments, like Mac. I'd also suggest Python, as an alternative option, were that possible.

For a 'standard' user though, as mentioned later in this thread, I'm not sure why they'd be learning to program in shell, let alone C. :lol:

Shell is far more powerful than most seem to realise, but having a good idea of its limitations is important as well. I think languages like Python seem to be a good halfway between effort and capability, which is why I sometimes use that, but I'm not that great at it. Shell, however -- now that's my passion, alongside Linux of course.

Ultimately though, I agree with other comments in this thread: it depends on the user.
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife

lmuserx4849

Re: C or Bash?

Post by lmuserx4849 » Tue Apr 17, 2018 2:29 pm

StevenC21 wrote:
Tue Apr 10, 2018 11:42 am
Which skill is more useful for a Linux user. Assume they are mutually exclusive, as in, you can only know and be proficient in one. Also, explain why; I want to increase my understanding. If this is the wrong forum please direct me to a good place for this.
Linux Kernel is the operating system (OS).

A Linux Distribution is the Linux OS plus additional layers of system and application software that run in the user space.

Folks use the term "linux" to mean a fully functioning computer, but that even means something different if you are talking about desktop, server, or even a IOT device. Linux is everywhere.

The shell is just one of those layers. Bash is one of many shells (Korn shell (ksh), C shell (csh), etc). When you type a command at a console you are using Bash.

Bash is not a programming language, it is a command interpreter. It is an interface between the user and the OS. It has program-like constructs to enable you to test the exit status of commands or process command output.

When you type: ls -l *.jpg, it is bash/readline that will process that line. The asterisk is called a glob (not to be mistaken for regular expression), each word is read in and expanded as necessary based on the IFS.

# Compiling a C progam from the command line could look like (you just used bash):
gcc myCpgm.c -o mycpgm && echo success || echo failure

Even if you use an IDE to develop your application and it hides these details from you, it is best that you learn what the blackbox is doing on your behalf.

How do you know which shell you are running: echo $0 or ps -p $$

Bottom line
If you are a regular user and only intend to use GUI's, you don't need to know bash or C, but imho you are limiting yourself and putting up unnecessary barriers to successfully using and exploiting all that a Linux system has to offer. You are missing out why many of us chose linux. It is fun. It is flexible. It is educational. It is challenging.

I'm guessing you are already using bash at the command line. I don't think a C-Programmer could get by without knowing a shell. If you type gcc at a console, you used bash :-)

You only need 3 resources to learn bash:
  1. The Linux Command Line, by William Shotts. You can buy his book or download it. Go through his two tutorials, "Learning the Shell" and "Writing Shell Scripts".
  2. The unofficial Bash FAQ.
  3. The bash man page and/or reference.


After that pick a programming language, C, java, python, even pascal or fortran....

If you want to contribute to an open source project, maybe even LM Cinnamon, I suspect python, C/C++, and/or javascript might be helpful. In most of these cases, the language is the easier part. It's all the libraries and frameworks that are more challenging. You don't learn C/C++ in a vacuum. If you are on KDE, you'd use QT. If you are on GNOME, you'd use GTK, ...

User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1439
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: C or Bash?

Post by Pilosopong Tasyo » Tue Apr 17, 2018 9:47 pm

StevenC21 wrote:
Tue Apr 10, 2018 3:56 pm
I did mean a standard user.
As a standard user, Bash will suffice. Every Linux user will encounter one form of shell scripting or another, sooner or later anyway.

C -- although touted as a [one of several] general-purpose programming languages -- is more geared towards developing simple as well as complex applications and system software. You deal with data structures and concepts that go beyond shell scripting.

Yeah, shell scripts are like writing DOS batch files... on steroids :lol:
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].

Post Reply

Return to “Scripts & Bash”