Lädt...

🐧 Beginner bash script question


Nachrichtenbereich: 🐧 Linux Tipps
🔗 Quelle: reddit.com

Hello guys, I am new to bash scripts and I have a task to write a BASH Shell script that receives two parameters: filename and directory name. It should report an error if there are no two parameters or if the first is not a file or if the second is not a directory. If the parameters are correct, the script should copy the file to the specified directory.

This what I've done:

#!/bin/bash if [ "$#" -ne 2 ] then echo "Error!"; elif [ ! -f $1 ] echo "Error!"; elif [ ! -d $2 ] echo "Error!"; else cp $1 $2; fi 

Is this okay? If not, can you tell me how should I correct it. Thank you in advance guys.

submitted by /u/temp000321
[link] [comments] ...

🔧 Bash Script Series: Automating Log Analysis with Bash Script or Shell Script


📈 39.21 Punkte
🔧 Programmierung

🔧 Bash Script Series: Automating Log Analysis with Bash Script or Shell Script


📈 39.21 Punkte
🔧 Programmierung

🐧 Beginner bash script question


📈 34.44 Punkte
🐧 Linux Tipps

🔧 Bash Script Series: The Mysterious Bash Script Challenge: A Fun and Creative Exploration


📈 32.45 Punkte
🔧 Programmierung

🐧 Bash Script Include Another Bash Script


📈 32.45 Punkte
🐧 Linux Tipps

🔧 Back to bash: Inception, running bash inside bash


📈 28.41 Punkte
🔧 Programmierung

🎥 Bash Scripting - BASH Scripts For Heavy Commandline Users [Bash Snippets]


📈 28.41 Punkte
🎥 IT Security Video

🎥 Bash Scripting - BASH Scripts For Heavy Commandline Users [Bash Snippets]


📈 28.41 Punkte
🎥 IT Security Video

🐧 niieani/bash-oo-framework: Bash Infinity is a modern boilerplate / framework / standard library for bash


📈 28.41 Punkte
🐧 Linux Tipps

🔧 What is the difference between Bash shells and the Bash Script?


📈 25.69 Punkte
🔧 Programmierung

🎥 What is a Bash Script? [13 of 20] | Bash for Beginners


📈 25.69 Punkte
🎥 Video | Youtube

📰 Bash add pause prompt in a shell script ( bash pause command )


📈 25.69 Punkte
🐧 Unix Server

🐧 Bash / Perl beginner script help


📈 24.66 Punkte
🐧 Linux Tipps

🐧 How can a bash script ssh command fail by just changing the script name?


📈 22.98 Punkte
🐧 Linux Tipps

🐧 VoidLinuxInstaller script, my first bash script!


📈 22.98 Punkte
🐧 Linux Tipps

📰 How to improve your bash/sh shell script with ShellCheck lint script analysis tool


📈 22.98 Punkte
🐧 Unix Server

🐧 Information about "'Script with Backup data in a certain time with BASH Script"


📈 22.98 Punkte
🐧 Linux Tipps

🐧 BASH Scripting Question


📈 19.25 Punkte
🐧 Linux Tipps

🐧 Does question marks have some kind of special meaning in bash and ZSH?


📈 19.25 Punkte
🐧 Linux Tipps

🎥 What is the difference between Cmd, PowerShell, and Bash? | One Dev Question


📈 19.25 Punkte
🎥 Video | Youtube

🎥 Next Steps with Bash [20 of 20] | Bash for Beginners


📈 18.94 Punkte
🎥 Video | Youtube

🐧 [WIP] The Pure Bash Bible - Documenting pure bash ways to do various tasks.


📈 18.94 Punkte
🐧 Linux Tipps

🎥 How to Navigate the Terminal with Bash [5 of 20] | Bash for Beginners


📈 18.94 Punkte
🎥 Video | Youtube

🎥 How to Use Redirection and Pipelines in Bash [11 of 20] | Bash for Beginners


📈 18.94 Punkte
🎥 Video | Youtube

🎥 How to Modify File Permissions in Bash [12 of 20] | Bash for Beginners


📈 18.94 Punkte
🎥 Video | Youtube

🎥 What are Variables in Bash? [14 of 20] | Bash for Beginners


📈 18.94 Punkte
🎥 Video | Youtube

🔧 bash coursera: intro shell bash scripting


📈 18.94 Punkte
🔧 Programmierung

🎥 How to Work with Directories in the Terminal with Bash [8 of 20] | Bash for Beginners


📈 18.94 Punkte
🎥 Video | Youtube

🔧 run.bash & migrate.bash - Pimpe deine .bashrc auf 🔝🔥


📈 18.94 Punkte
🔧 Programmierung

matomo