Xcode +Terminal

Discussion in 'Mac Programming' started by Keytachi, May 15, 2007.

  1. Keytachi macrumors regular

    Joined:
    Sep 14, 2006
    #1
    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
     
  2. janey macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
    #2
    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.
     
  3. cruzrojas macrumors member

    cruzrojas

    Joined:
    Mar 26, 2007
    Location:
    USA
    #3
    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
     
  4. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #4
    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.
     
  5. Keytachi thread starter macrumors regular

    Joined:
    Sep 14, 2006
    #5
    So i would need to progrm something in, lets say, C++ and inside those codes, enter the terminal ones?
     
  6. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #6
    Yes, I'd have thought you can in any language. You can definitely do it in both Java and Applescript.
     
  7. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #7
    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.

    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.
     
  8. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #8
    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".
     
  9. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #9
    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
     
  10. cube macrumors G5

    Joined:
    May 10, 2004
    #10
    The world simplest program is in Lisp:

    Code:
    "Hello World"
    Unless you find a language where the quotes are not necessary.
     
  11. soup4you2 macrumors regular

    Joined:
    Apr 12, 2007
    #11
    Actually the default shell is Bash you can type in echo $SHELL to verify that.

    and i think what your looking for is more scripting than programming.

    Here's a good reference guide for writing shell scripts.

    http://www.tldp.org/LDP/abs/html/
     
  12. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #12
    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.
    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.

    Just google bash shell scripting.
     
  13. cruzrojas macrumors member

    cruzrojas

    Joined:
    Mar 26, 2007
    Location:
    USA
    #13
    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.
     
  14. Keytachi thread starter macrumors regular

    Joined:
    Sep 14, 2006
    #14
    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).
    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
     
  15. janey macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
    #15
    Code:
    cd /path/to/folder/containing/script
    chmod +x filename
    ./filename
     
  16. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #16
    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".
     
  17. slooksterPSV macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #17
    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.
     
  18. janey macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
    #18
    couldn't you just add to PATH? so you can just type 'app_name' and it'll work...

    or am i missing the point :D
     
  19. slooksterPSV macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #19
    You're absolutely right, and then have a script that runs when you start up terminal to set that path.
     
  20. janey macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
    #20
    or just echo $PATH="$PATH:/anotherpath:/someotherpath" in ~/.bash_profile
     

Share This Page