Welcome to the Linux Foundation Forum!
Deciphering lines of code
Coyote1967
Posts: 1
Hey everyone I don't know if this is the right place to ask this question but I am trying to learn what different lines of code do and I need some help. I am looking at the Save command specifically. It was written to save files and back then up to a directory for later backup usage. The problem that I am having is in the first part of the code. For instance on this line
if [! -d $1];then echo $1 is not a directory; exit 1; fi
I know the fi means that the line is finished and the echo is a command to run the $1 file but what is the first part? Any help will be appreciated. Thanks
0
Comments
-
Well fi actually marks the end of the if statement (it's just "if" backwards). The [! -d $1] is performing a test on a passed value, which is being referred to by $1 (the 1st parameter). -d tests to see whether it is a directory. The ! negates the statement to make it check whether it is not a directory.
In English, it's saying "If the parameter passed is not a directory, then say '[value of parameter passed] is not a directory."
Here are more options you can use (although probably not a complete list):-e file -s non-empty file -b block device -c character device -f a non-directory and non-device file -p pipe -h symbolic link -r file has read permission -w file has write permission -x file has execute permission -k has sticky bit set -O you are the file owner -G same group as you -N modified since last read
0 -
Oh, I should have clarified the square brackets. Those just indicate that a test is being performed inside them, and it will return 0 (true) or 1 (false) to the if clause.0
Categories
- All Categories
- 179 LFX Mentorship
- 179 LFX Mentorship: Linux Kernel
- 777 Linux Foundation IT Professional Programs
- 384 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 76 DevOps IT Professional Program - Discontinued
- 7 DevOps & GitOps IT Professional Program
- 104 Cloud Native Developer IT Professional Program
- 7.7K Training Courses & Learning Paths
- 21 AI & ML Training
- 2 Blockchain & Decentralized Identity Training
- 52 Cloud & Containers Training
- 7 Cybersecurity Training
- 5 DevOps & Site-Reliability Training
- 3 Linux Kernel Development Training
- 3 Networking Training
- 2 Open Source Best Practice Training
- 10 System Administration Training
- 1 System Engineering Training
- 6 Web & Application Development Training
- 799 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 97 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 92 Storage
- 776 Linux Distributions
- 83 Debian
- 68 Fedora
- 25 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 32 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 473 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 104 Linux Security
- 79 Network Management
- 102 System Management
- 46 Web Management
- 190 Mobile Computing
- 32 Android
- 142 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 407 Off Topic
- 128 Introductions
- 35 Study Material
- 1.1K Programming and Development
- 312 Kernel Development
- 735 Software Development
- 1K Software
- 421 Applications
- 183 Command Line
- 5 Compiling/Installing
- 71 Games
- 320 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)