Zsh 명령어 스크립트 예시

Zsh, also known as Z shell, is a powerful command-line interpreter for Unix and Linux systems. It offers improved functionality and customization options compared to the traditional Bash shell. In this blog post, we will explore some sample Zsh command scripts to give you a better understanding of its capabilities.

1. Hello World Script

Let’s start with a simple “Hello World” script in Zsh:

#!/bin/zsh

echo "Hello, World!"

Save the above script in a file called hello.zsh. Make it executable using the chmod +x hello.zsh command. Then, run the script using ./hello.zsh, and you should see the output: “Hello, World!”.

2. Loop Script

Zsh supports various looping constructs. Here’s an example of a for loop that iterates over a list of numbers:

#!/bin/zsh

for i in {1..5}
do
    echo "Number: $i"
done

Save the above script in a file called loop.zsh, make it executable, and run it. You will see the output:

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5

3. Command Line Arguments

Zsh allows you to pass arguments to your scripts from the command line. Here’s an example:

#!/bin/zsh

echo "Script Name: $0"
echo "First Argument: $1"
echo "Second Argument: $2"

Save the above script in a file called args.zsh, make it executable, and run it with two arguments: ./args.zsh Hello World. You will see the output:

Script Name: ./args.zsh
First Argument: Hello
Second Argument: World

Conclusion

Zsh provides a powerful scripting environment with numerous features and customization options. In this blog post, we explored a few examples to get you started with Zsh scripting. Whether you are a beginner or an experienced user, Zsh can greatly enhance your command-line experience on Linux and Unix systems.

Remember to experiment and explore more about Zsh scripts. It’s a vast topic with endless possibilities. Happy scripting!