Help with terminal project in Mac

In summary, the conversation discusses the use of a command file to navigate to a specific folder, create a file within that folder, and accept an argument for the creation of another file. The concept of passing arguments into a batch file is also mentioned.
  • #1
Huumah
28
0
Hi
I'm learning how to use terminal at school but there is one part of my assignment
Write a command file (a .bat file on Windows, an .sh file on OSX/*nix) containing the following command:

1. navigate to the folder C:\Temp (you may assume it exists, you should create it on your own computer if it doesn't). Note: Linux and Mac users should pick some other temporary folder, such as /tmp.
2. create a file within that folder called "Example.txt". This file may be empty, or it may contain some text.
3. create another file, which name should not be hardcoded, but should be accepted as an argument to the batch file

My attempt:

Code:
cd /Users/tmp

echo "New file" >Example.txt
I can't really understand task number 3. Can anyone help me?
 
Physics news on Phys.org
  • #2
If you have a command file (say Print.bat) that is designed to perform an operation on another file (eg print it) then you don't want to have to edit the command file every time you want to print a different file. You want to be able to tell it the name of the file to print when you actually run it. To do this you put the name of the file you want printed in the command line when you run it. This is called "passing an argument" or "passing a parameter".

Google "passing arguments into a batch file" without the quotes.
 

Related to Help with terminal project in Mac

1. What is a terminal project in Mac?

A terminal project in Mac is a project that involves using the Terminal application on a Mac computer to execute commands and perform tasks. The Terminal application allows users to interact with their computer's operating system through a command-line interface.

2. How do I access the Terminal application in Mac?

To access the Terminal application in Mac, you can either open it from the Applications folder or use the keyboard shortcut "Command + Space" to open the Spotlight search and type in "Terminal" to open it.

3. What are some common commands used in the Terminal?

Some common commands used in the Terminal include "cd" to change directories, "ls" to list files and folders, "mkdir" to create a new directory, "cp" to copy files, "mv" to move files, and "rm" to remove files or directories.

4. How do I navigate through folders and files in the Terminal?

To navigate through folders and files in the Terminal, you can use the "cd" command followed by the name of the folder you want to move into. To move up one level, you can use "cd .." and to move to the previous directory, you can use "cd -". You can also use the "ls" command to view the contents of the current directory.

5. What resources are available for help with Terminal projects in Mac?

There are many resources available for help with Terminal projects in Mac, including online tutorials, forums, and documentation provided by Apple. You can also use the "man" command in the Terminal to access the manual pages for specific commands and their usage. Additionally, there are third-party applications and tools that can make working with the Terminal easier and more efficient.

Similar threads

  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
Replies
16
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
  • Special and General Relativity
Replies
6
Views
5K
  • Programming and Computer Science
Replies
8
Views
8K
Replies
14
Views
3K
  • Special and General Relativity
Replies
1
Views
2K
Back
Top