Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Keytachi

macrumors regular
Original poster
Sep 14, 2006
161
0
I have a few questions:
1. What language does terminal recognizes, i mean, the command I type in (sudo, etc.) what language is that?
2. Is it possible to create an app with Xcode (or other app) with terminal's code? E.g. Compiling some binaries, only pressing a button (the app would run the required commands). The GUI would come later, first i just wanted to know if it was possible.
3. If it is possible, how should i do it? Please just give me some topics, for I would like to do it myself.

Thank you,
Key
 

janey

macrumors 603
Dec 20, 2002
5,316
0
sunny los angeles
1. that's not a language, that's a program called "sudo".
2. yes it is, but depending on which language, you might want to use more suitable tools.
3. again, more info please.
 

cruzrojas

macrumors member
Mar 26, 2007
67
0
USA
What you are talking about is the terminal. In the terminal you can type commands and the system will execute those commands, ie. sudo. There is not really a programming lenguage but you can create batch processes. That means a list of commands executed one after the other, for example the list of commands needed to compile, link an execute a cpp file. What are you looking for is know as shell script or bash programming.

I hope this helps.
Best Regards
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
It is possible to write an application that will use commands from the terminal. For example, in C and C++ and ObjC the system() function will take as an argument a command and will execute it as if it was typed inside the terminal.
 

Keytachi

macrumors regular
Original poster
Sep 14, 2006
161
0
So i would need to progrm something in, lets say, C++ and inside those codes, enter the terminal ones?
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Yes, I'd have thought you can in any language. You can definitely do it in both Java and Applescript.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
I have a few questions:
1. What language does terminal recognizes, i mean, the command I type in (sudo, etc.) what language is that?
As has been pointed out, that's a Terminal command, not a language, but built in Terminal commands are usually written in C/C++. However you can write scripts using eg. python or perl, or put together collections of standard unix commands, that look to the user just like Terminal commands.

To write a command line program in C/C++ you need to parse the input arguments that come in via "void main(char[][] args)" in your main program.

2. Is it possible to create an app with Xcode (or other app) with terminal's code? E.g. Compiling some binaries, only pressing a button (the app would run the required commands). The GUI would come later, first i just wanted to know if it was possible.
I think you're thinking of writing a library and linking it into a GUI that you'll design and implement later. Yes, you can do this without XCode, just building the library using gcc or g++ and linking a main program with the library for use in the Terminal. Then build your GUI in XCode and link to the library.

However, unless you're thinking about general Unix programming skills that you can bring across to eg. Linux, I suggest you just buy a Mac programming book and use XCode to build your GUI from the start.
 

ChrisA

macrumors G5
Jan 5, 2006
12,907
2,155
Redondo Beach, California
I have a few questions:
1. What language does terminal recognizes, i mean, the command I type in (sudo, etc.) what language is that?
2. Is it possible to create an app with Xcode (or other app) with terminal's code? E.g. Compiling some binaries, only pressing a button (the app would run the required commands). The GUI would come later, first i just wanted to know if it was possible.
3. If it is possible, how should i do it? Please just give me some topics, for I would like to do it myself.

Thank you,
Key

1) The thing that accepts commands like "sudo" is caled a "shell". There are several shells. the default one is called ""sh" and the language is named for the shell in this case "sh" but you can have "csh", ksh or a few others. Which one comes up inside the terminal is determined by an entry in the password file (/etc/passwd)

You can read about the sh language by typing "man sh". It is actually a quite powerfull scripting language, useful for many things.

You don't "compile" sh programs. just save the text file.
You do need a special comment in the first line. Here is a world's simplest "program"

#! /bin/sh
echo "hello world"

Put those lines in a file, set it executable then type the file's name and it will run and print out "hello world".
 

ChrisA

macrumors G5
Jan 5, 2006
12,907
2,155
Redondo Beach, California
What you are talking about is the terminal. In the terminal you can type commands and the system will execute those commands, ie. sudo. There is not really a programming lenguage but you can create batch processes.

bash runs inside the terminal, if bash is not a programming language then what is? Bash has "if" statements, for and while loops, arithmetic and assignment statements and so on. what's missing? Maybe you like Python of C++ better but bash is a full on complete programming language. I've seen some fairly large applications written in sh. One example would be those .configure scripts that the GNU Autotools make
 

cube

Suspended
May 10, 2004
17,011
4,973
Here is a world's simplest "program"

#! /bin/sh
echo "hello world"

The world simplest program is in Lisp:

Code:
"Hello World"

Unless you find a language where the quotes are not necessary.
 

SC68Cal

macrumors 68000
Feb 23, 2006
1,642
0
I have a few questions:
1. What language does terminal recognizes, i mean, the command I type in (sudo, etc.) what language is that?

The default shell in Terminal is the Bash shell, which uses the Bash scripting language. I'm not 100% sure on other languages that Bash understands, but I know some shells like the Korn shell understand C. Check Bash's documentation.
2. Is it possible to create an app with Xcode (or other app) with terminal's code? E.g. Compiling some binaries, only pressing a button (the app would run the required commands). The GUI would come later, first i just wanted to know if it was possible.

Yeah, I'm sure at the basic level you can create bash shell scripts with Xcode, but frankly you might as well just use a regular plain text editor, since there is no compiling.

3. If it is possible, how should i do it? Please just give me some topics, for I would like to do it myself.

Just google bash shell scripting.
 

cruzrojas

macrumors member
Mar 26, 2007
67
0
USA
bash runs inside the terminal, if bash is not a programming language then what is? Bash has "if" statements, for and while loops, arithmetic and assignment statements and so on. what's missing? Maybe you like Python of C++ better but bash is a full on complete programming language. I've seen some fairly large applications written in sh. One example would be those .configure scripts that the GNU Autotools make

Well, when I said is not really a programming language I meant that it is considered an scripting language. You can do really powerfull things with it as you mentioned, but there are some limitations as with any language.

I don't know exactly what are the differences between a scripting language and a programming language but there is a few of them.

Best Regards.
 

Keytachi

macrumors regular
Original poster
Sep 14, 2006
161
0
Let's see if i got this straight:
Terminal does not use a programming language, but a sripting language.
I can do a shell script, and then run it in terminal (instead of typing many commands).
#! /bin/sh
echo "hello world"

Put those lines in a file, set it executable then type the file's name and it will run and print out "hello world".
How do i set it executable? Is there a specific place i need to put it in?

Thank you all for the replies, you have been very helpful!
Key
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
I have a few questions:
1. What language does terminal recognizes, i mean, the command I type in (sudo, etc.) what language is that?

Everything you type into terminal is interpreted by the bash shell. Google for "bash", and the third hit or so is the official "bash reference manual".
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
Now just to give you some prospect to this whole Terminal thing here's my 2 cents on it. I've created a program to where all I have to type in is makeapp ./main.cpp myApp but I used a terminal script and copied it into a place where users should not copy items unless they know what they're doing. E.g. the bin folder. Now you can make apps and put them in there so you can just type them in terminal and have them execute without having to call ./app_name so yeah.

Now as for C++ executing commands.... I dunno if there is a way, but you may be able to write code to do it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.