Help with terminal project in Mac

  • Thread starter Thread starter Huumah
  • Start date Start date
  • Tags Tags
    Mac Project
Click For Summary
SUMMARY

The discussion focuses on creating a shell script (.sh file) for Mac that performs specific file operations in the terminal. The user is tasked with navigating to a temporary folder, creating a file named "Example.txt", and creating another file whose name is passed as an argument. The user correctly navigates to the folder and creates "Example.txt" but seeks clarification on how to implement the functionality of passing an argument for the second file's name. The concept of "passing an argument" is highlighted as essential for dynamic file operations in shell scripting.

PREREQUISITES
  • Basic knowledge of terminal commands in macOS
  • Understanding of shell scripting (.sh files)
  • Familiarity with file manipulation commands like 'echo' and 'cd'
  • Concept of passing arguments in scripts
NEXT STEPS
  • Learn how to create and execute shell scripts in macOS
  • Research the 'read' command in shell scripting for user input
  • Explore the use of positional parameters in shell scripts
  • Study examples of passing arguments to scripts in Unix/Linux environments
USEFUL FOR

Students learning terminal commands, aspiring developers interested in shell scripting, and anyone looking to automate file operations in macOS.

Huumah
Messages
27
Reaction score
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
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
6K
Replies
16
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 8 ·
Replies
8
Views
9K
Replies
14
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K