This document provides information on shell operators in 3 sections:
1) It discusses arithmetic operators and how to perform arithmetic evaluations in the shell using expr and $((expression)).
2) It covers relational operators for numeric comparisons and conditional statements.
3) It describes string, file test, and boolean operators for evaluating strings and conditions.
Regular Expressions: JavaScript And BeyondMax Shirshin
Regular Expressions is a powerful tool for text and data processing. What kind of support do browsers provide for that? What are those little misconceptions that prevent people from using RE effectively?
The talk gives an overview of the regular expression syntax and typical usage examples.
Regular Expressions: JavaScript And BeyondMax Shirshin
Regular Expressions is a powerful tool for text and data processing. What kind of support do browsers provide for that? What are those little misconceptions that prevent people from using RE effectively?
The talk gives an overview of the regular expression syntax and typical usage examples.
Outline of this lecture:
- Relational operators
- Bitwise operators
- Logical operators
- Assignment operators
- Miscellaneous operators
- If/else statements
- Loop control
- Number Class
- Number class methods
- Character class
- Character class methods
- Scanner class
This presentation contain description about C Operators.
It explains Arithmetic operators, relational operators, logical operators, increment/decrement operators, conditional and bitwise operators are explained with example.
Learning to write programs using selection
Condition: Relational and Logical Expressions , Conditional Statements (if statement) , Choosing from Multiple Alternatives
Exercises in writing conditions using relational, logical operations, writing programs involving if statement, if-else, if- elseif and switch case statements in MATLAB
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
3. Arithmetic Operators
Bourne shell didn't originally have any mechanism to perform simple arithmetic
It uses external programs - awk or program expr.
#!/bin/sh
val=`expr 2 + 2`
echo "Total value : $val"
result:
Total value : 4
• There must be spaces between operators and expressions 2+2 is not correct.
it should be written as 2 + 2.
• Complete expression should be enclosed between `` (inverted commas)
4. Arithmetic Operators
Ex. variable a holds 10 and variable b holds 20 then:
+ Addition - Adds values on either side of the operator
`expr $a + $b` will give 30
- Subtraction - Subtracts right hand operand from left hand operand
`expr $a - $b` will give -10
* Multiplication - Multiplies values on either side of the operator
`expr $a * $b` will give 200
/ Division - Divides left hand operand by right hand operand
`expr $b / $a` will give 2
% Modulus - Divides left hand operand by right hand operand and returns remainder
`expr $b % $a` will give 0
= Assignment - Assign right operand in left operand
a=$b would assign value of b into a
== Equality - Compares two numbers, if both are same then returns true.
[ $a == $b ] would return false
!= Not Equality - Compares two numbers, if both are different then returns true.
[ $a != $b ] would return true
All conditional expressions are put inside square braces with one spaces around them.
[ $a == $b ] is correct; [$a==$b] is incorrect.
All the arithmetical calculations are done using long integers.
5. Arithmetic expressions
#!/bin/sh
a=10
b=20
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a * $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
if [ $a == $b ]
then
echo "a is equal to b"
fi
if [ $a != $b ]
then
echo "a is not equal to b"
fi
Exemple
6. Arithmetic expressions
a + b : 30
a - b : -10
a * b : 200
b / a : 2
b % a : 0
a is not equal to b
Exemple Result
• There must be spaces between operators and expressions 2+2 is not
correct, as it should be written as 2 + 2.
• Complete expression should be enclosed between `` (inverted commas)
• use on the * symbol for multiplication.
• if...then...fi statement is a decision making statement (for later lessons:-)
7. Arithmetic expressions
$ let X=10+2*7
$ echo $X
24
$ let Y=X+2*4
$ echo $Y
32
The let statement can be used to do mathematical functions
$ echo “$((123+20))”
143
$ VALORE=$[123+20]
$ echo “$[123*$VALORE]”
17589
arithmetic expression can be evaluated with $[expression] or $((expression))
8. Arithmetic expressions
$ vi arithmetic.sh
#!/bin/bash
echo -n “Enter the first number: ”; read x
echo -n “Enter the second number: ”; read y
add=$(($x + $y))
sub=$(($x - $y))
mul=$(($x * $y))
div=$(($x / $y))
mod=$(($x % $y))
Echo ”sum: $add”…
Exemple
echo “Sum: $add”
echo “Difference: $sub”
echo “Product: $mul”
echo “Quotient: $div”
echo “Remainder: $mod”
Exemple Result
9. Conditional Statements
Conditionals let us decide whether to perform an action or not this decision
is taken by evaluating an expression.
basic form:
if [ expression ];
then
statements
elif [ expression ];
then
statements
else
statements
fi
the elif (else if) and else sections are optional
Put spaces after [ and before ], and around the operators and operands.
10. Expressions
An expression can be:
• String comparison
• Numeric comparison
• File operators
• Logical operators
An expression is represented by $[expression] or $((expression))
11. Relational Operators
Number Comparisons Expression
Bourne Shell supports relational operators which are specific to numeric values
These operators do not work for string values unless their value is numeric.
For example, following operators would work to check a relation between 10 and 20 as well as in
between "10" and "20" but not in between "ten" and "twenty".
eq Check if value of two operands are equal or not, if yes then condition becomes
true. [ $a -eq $b ] is not true.
-ne If value of two operands are equal or not, if values are not equal then condition
becomes true. [ $a -ne $b ] is true.
-gt If the value of left operand is greater than the value of right operand, if yes then
condition becomes true. [ $a -gt $b ] is not true.
-lt If the value of left operand is less than the value of right operand, if yes then
condition becomes true. [ $a -lt $b ] is true.
-ge If the value of left operand is greater than or equal to the value of right operand, if
yes then condition becomes true. [ $a -ge $b ] is not true.
-le If the value of left operand is less than or equal to the value of right operand, if yes
then condition becomes true. [ $a -le $b ] is true.
Ex. variable a holds 10 and variable b holds 20 then:
All conditional expressions would be put inside square braces with one spaces around them
[ $a <= $b ] is correct , [$a <= $b] is incorrect.
12. Relational Operators
Number Comparisons Expression
Simple Table
-eq compare if two numbers are equal
-ge compare if one number is greater than or equal to a number
-le compare if one number is less than or equal to a number
-ne compare if two numbers are not equal
-gt compare if one number is greater than another number
-lt compare if one number is less than another number
[ n1 -eq n2 ] (true if n1 same as n2, else false)
[ n1 -ge n2 ] (true if n1greater then or equal to n2, else false)
[ n1 -le n2 ] (true if n1 less then or equal to n2, else false)
[ n1 -ne n2 ] (true if n1 is not same as n2, else false)
[ n1 -gt n2 ] (true if n1 greater then n2, else false)
[ n1 -lt n2 ] (true if n1 less then n2, else false)
13. Relational Operators
Number Comparisons Expression
#!/bin/sh
a=10
b=20
if [ $a -eq $b ]
then
echo "$a -eq $b : a is equal to b"
else
echo "$a -eq $b: a is not equal to b"
fi
if [ $a -ne $b ]
then
echo "$a -ne $b: a is not equal to b"
else
echo "$a -ne $b : a is equal to b"
fi
if [ $a -gt $b ]
then
echo "$a -gt $b: a is greater than b"
else
echo "$a -gt $b: a is not greater than b"
fi
if [ $a -lt $b ]
then
echo "$a -lt $b: a is less than b"
else
echo "$a -lt $b: a is not less than b"
fi
if [ $a -ge $b ]
then
echo "$a -ge $b: a is greater or equal to b"
else
echo "$a -ge $b: a is not greater or equal
to b"
fi
if [ $a -le $b ]
then
echo "$a -le $b: a is less or equal to b"
else
echo "$a -le $b: a is not less or equal to b"
fi
Exemple
14. Relational Operators
Number Comparisons Expression
10 -eq 20: a is not equal to b
10 -ne 20: a is not equal to b
10 -gt 20: a is not greater than b
10 -lt 20: a is less than b
10 -ge 20: a is not greater or equal to b
10 -le 20: a is less or equal to b
Exemple Result
15. Relational Operators
Number Comparisons Expression
Exemple
$ vi number.sh
#!/bin/bash
echo -n “Enter a number 1 < x < 10: "
read num
if [ “$num” -lt 10 ]; then
if [ “$num” -gt 1 ]; then
echo “$num*$num=$(($num*$num))”
else
echo “Wrong insertion !”
fi
else
echo “Wrong insertion again !”
fi
16. String Operators
String Comparisons Expressions
= Checks if value of two operands are equal or not, if yes then condition becomes true.
[ $a = $b ] is not true.
!= Checks if the value of two operands are equal or not, if values are not equal then
condition becomes true.
[ $a != $b ] is true.
-z Checks if the given string operand size is zero. If it is zero length then it returns true.
[ -z $a ] is not true.
-n Checks if the given string operand size is non-zero. If it is non-zero length then it
returns true.
[ -z $a ] is not false.
Str Check if str is not the empty string. If it is empty then it returns false.
[ $a ] is not false.
Ex. variable a holds “abc” and variable b holds “efg” then:
17. String Operators
String Comparisons Expressions
Simple Table
= compare if two strings are equal
!= compare if two strings are not equal
-n evaluate if string length is greater than zero
-z evaluate if string length is equal to zero
[ s1 = s2 ] (true if s1 same as s2, else false)
[ s1 != s2 ] (true if s1 not same as s2, else false)
[ s1 ] (true if s1 is not empty, else false)
[ -n s1 ] (true if s1 has a length greater then 0, else false)
[ -z s2 ] (true if s2 has a length of 0, otherwise false)
18. String Operators
String Comparisons Expressions
#!/bin/sh
a="abc"
b="efg"
if [ $a = $b ]
then
echo "$a = $b : a is equal to b"
else
echo "$a = $b: a is not equal to b"
fi
if [ $a != $b ]
then
echo "$a != $b : a is not equal to b"
else
echo "$a != $b: a is equal to b"
fi
Exemple
if [ -z $a ]
then
echo "-z $a : string length is zero"
else
echo "-z $a : string length is not zero"
fi
if [ -n $a ]
then
echo "-n $a : string length is not zero"
else
echo "-n $a : string length is zero"
fi
if [ $a ]
then
echo "$a : string is not empty"
else
echo "$a : string is empty"
fi
19. String Operators
String Comparisons Expressions
abc = efg: a is not equal to b
abc != efg : a is not equal to b
-z abc : string length is not zero
-n abc : string length is not zero
abc : string is not empty
Exemple Result
20. String Operators
String Comparisons Expressions
$ vi user.sh
#!/bin/bash
echo -n “Enter your login name: "
read name
if [ “$name” = “$USER” ];
then
echo “Hello, $name. How are you today ?”
else
echo “You are not $USER, so who are you ?”
fi
Exemple
21. Boolean Operators
Logical operators Expressions
! This is logical negation.
This inverts a true condition into false and vice versa.
[ ! false ] is true.
-o This is logical OR.
If one of the operands is true then condition would be true.
[ $a -lt 20 -o $b -gt 100 ] is true.
-a This is logical AND.
If both the operands are true then condition would be true otherwise it would be false.
[ $a -lt 20 -a $b -gt 100 ] is false.
Ex. variable a holds 10 and variable b holds 20 then:
22. Boolean Operators
Logical operators Expressions
Simple Table
! negate (NOT) a logical expression
-a logically AND two logical expressions
-o logically OR two logical expressions
#!/bin/bash
echo -n “Enter a number 1 < x < 10:”
read num
if [ “$num” -gt 1 –a “$num” -lt 10 ];
then
echo “$num*$num=$(($num*$num))”
else
echo “Wrong insertion !”
fi
Exemple
23. Boolean Operators
Logical operators Expressions
a=10
b=20
if [ $a != $b ]
then
echo "$a != $b : a is not equal to b"
else
echo "$a != $b: a is equal to b"
fi
if [ $a -lt 100 -a $b -gt 15 ]
then
echo "$a -lt 100 -a $b -gt 15 : returns true"
else
echo "$a -lt 100 -a $b -gt 15 : returns false"
fi
if [ $a -lt 100 -o $b -gt 100 ]
then
echo "$a -lt 100 -o $b -gt 100 : returns true"
else
echo "$a -lt 100 -o $b -gt 100 : returns false"
fi
if [ $a -lt 5 -o $b -gt 100 ]
then
echo "$a -lt 100 -o $b -gt 100 : returns true"
else
echo "$a -lt 100 -o $b -gt 100 : returns false"
fi
Exemple
24. Boolean Operators
Logical operators Expressions
10 != 20 : a is not equal to b
10 -lt 100 -a 20 -gt 15 : returns true
10 -lt 100 -o 20 -gt 100 : returns true
10 -lt 5 -o 20 -gt 100 : returns false
Exemple Result
25. File Test Operators
Boolean Check condition
-b file Checks if file is a block special file if yes then condition becomes true. [ -b $file ] is false
-c file Checks if file is a character special file if yes then condition becomes true. [ -b $file ] is false
-d file Check if file is a directory if yes then condition becomes true. [ -d $file ] is not true
-f file Check if file is an ordinary file as opposed to a directory or special file if yes then condition becomes true
[ -f $file ] is true
-g file Checks if file has its set group ID (SGID) bit set if yes then condition becomes true. [ -g $file ] is false
-k file Checks if file has its sticky bit set if yes then condition becomes true. [ -k $file ] is false
-p file Checks if file is a named pipe if yes then condition becomes true. [ -p $file ] is false
-t file Checks if file descriptor is open and associated with a terminal if yes then condition becomes true
[ -t $file ] is false
-u file Checks if file has its set user id (SUID) bit set if yes then condition becomes true. [ -u $file ] is false
-r file Checks if file is readable if yes then condition becomes true. [ -r $file ] is true
-w file Check if file is writable if yes then condition becomes true. [ -w $file ] is true
-x file Check if file is execute if yes then condition becomes true. [ -x $file ] is true
-s file Check if file has size greater than 0 if yes then condition becomes true. [ -s $file ] is true
-e file Check if file exists. Is true even if file is a directory but exists. [ -e $file ] is true
Ex. file holds an existing file name "test" whose size is 100 bytes and has read, write and execute permission on
26. File Test Operators
Boolean Check condition
Simple Table
-d check if path given is a directory
-f check if path given is a file
-e check if file name exists
-r check if read permission is set for file or directory
-s check if a file has a length greater than 0
-w check if write permission is set for a file or directory
-x check if execute permission is set for a file or directory
[ -d scripts ] (true if scripts is a directory, otherwise false)
[ -f scripts ] (true if scripts is a file, otherwise false)
[ -e scripts ] (true if scripts exists, otherwise false)
[ -s scripts ] (true if scripts length is greater then 0, else false)
[ -r scripts ] (true if scripts has the read permission, else false)
[ -w scripts ] (true if scripts has the write permission, else false)
[ -x scripts ] (true if scripts has the execute permission, else false)
27. File Test Operators
Boolean Check condition
#!/bin/bash
if [ -f /etc/fstab ];
then
cp /etc/fstab .
echo “Done.”
else
echo “This file does not exist.”
exit 1
fi
Exemple
28. File Test Operators
Boolean Check condition
Exercice
Write a shell script which:
• accepts a file name
• checks if file exists
• if file exists, copy the file to the same name + .bak + the current date
(if the backup file already exists ask if you want to replace it)
When done you should have the original file and one with a .bak at the end.
29. File Test Operators
Boolean Check condition
Exemple
Assume a variable file holds an existing file name "/root/scripts/user.sh" whose size is 100
bytes and has read, write and execute permission on:
#!/bin/sh
file="/root/scripts/user.sh"
if [ -r $file ]
then
echo "File has read access"
else
echo "File does not have read access"
fi
if [ -w $file ]
then
echo "File has write permission"
else
echo "File does not have write permission"
fi
if [ -x $file ]
then
echo "File has execute permission"
else
echo "File does not have execute permission"
fi
if [ -f $file ]
then
echo "File is an ordinary file"
else
echo "This is special file"
fi
if [ -d $file ]
then
echo "File is a directory"
else
echo "This is not a directory"
fi
if [ -s $file ]
then
echo "File size is zero"
else
echo "File size is not zero"
fi
if [ -e $file ]
then
echo "File exists"
else
echo "File does not exist"
fi
30. File Test Operators
Boolean Check condition
File has read access
File has write permission
File has execute permission
File is an ordinary file
This is not a directory
File size is zero
File exists
Exemple Result
31. C Shell Operators
Arithmetic and Logical Operators
( ) Change precedence
~ 1's complement
! Logical negation
* Multiply
/ Divide
% Modulo
+ Add
- Subtract
<< Left shift
>> Right shift
== String comparison for equality
!= String comparison for non equality
=~ Pattern matching
& Bitwise "and"
^ Bitwise "exclusive or"
| Bitwise "inclusive or"
&& Logical "and"
|| Logical "or"
++ Increment
-- Decrement
= Assignment
*= Multiply left side by right side and update left
side
/= Divide left side by right side and update left
side
+= Add left side to right side and update left side
-= Subtract left side from right side and update left side
^= "Exclusive or" left side to right side and update
left side
%= Divide left by right side and update left side
with remainder
32. C Shell Operators
File Test Operators
-r file Checks if file is readable if yes then condition becomes true.
-w file Check if file is writable if yes then condition becomes true.
-x file Check if file is execute if yes then condition becomes true.
-f file Check if file is an ordinary file as opposed to a directory or special file if yes
then condition becomes true.
-z file Check if file has size greater than 0 if yes then condition becomes true.
-d file Check if file is a directory if yes then condition becomes true.
-e file Check if file exists. Is true even if file is a directory but exists.
-o file Check if user owns the file. It returns true if user is the owner of the file.
33. Korn Shell Operators
Arithmetic and Logical Operators
+ Unary plus
- Unary minus
!~ Logical negation; binary inversion (one's complement)
* Multiply
/ Divide
% Modulo
+ Add
- Subtract
<< Left shift
>> Right shift
== String comparison for equality
!= String comparison for non equality
=~ Pattern matching
& Bitwise "and"
^ Bitwise "exclusive or"
| Bitwise "inclusive or"
&& Logical "and"
|| Logical "or"
++ Increment
-- Decrement
= Assignment
34. Korn Shell Operators
File Test Operators
-r file Checks if file is readable if yes then condition becomes true.
-w file Check if file is writable if yes then condition becomes true.
-x file Check if file is execute if yes then condition becomes true.
-f file Check if file is an ordinary file as opposed to a directory or special file if yes
then condition becomes true.
-s file Check if file has size greater than 0 if yes then condition becomes true.
-d file Check if file is a directory if yes then condition becomes true.
-e file Check if file exists. Is true even if file is a directory but exists.
35. Korn/C Shell Logical Operators
Exemple
#!/bin/bash
echo -n "Enter a number 1 < x < 10: "
read num
if [ “$number” -gt 1 ] && [ “$number” -lt 10 ];
then
echo “$num*$num=$(($num*$num))”
else
echo “Wrong insertion !”
fi
36. Exemple
$ vi iftrue.sh
#!/bin/bash
echo “Enter a path: ”; read x
if cd $x; then
echo “I am in $x and it contains”; ls
else
echo “The directory $x does not exist”;
exit 1
fi
$ iftrue.sh
Enter a path: /home
userid otherid …
$ iftrue.sh
Enter a path: blah
The directory blah does not exist
37. Shell Parameters
Positional parameters
Variable Description
$0 The filename of the current script.
$n These variables correspond to the arguments with which a script was invoked.
Here n is a positive decimal number corresponding to the position of an argument
(the first argument is $1, the second argument is $2, and so on).
$# The number of arguments supplied to a script.
$* All the arguments are double quoted. If a script receives two arguments, $* is
equivalent to $1 $2.
$@ All the arguments are individually double quoted. If a script receives two
arguments, $@ is equivalent to $1 $2.
$? The exit status of the last command executed.
$$ The process number of the current shell. For shell scripts, this is the process ID
under which they are executing.
$! The process number of the last background command.
38. Positional parameters are assigned from the shell’s argument when it is invoked.
Positional parameter “N” may be referenced as “${N}”,
or as “$N” when “N” consists of a single digit.
$# is the number of parameters passed
$0 returns the name of the shell script running as well as its location in the file system
$* gives a single word containing all the parameters passed to the script
$@ gives an array of words containing all the parameters passed to the script
$ cat sparameters.sh
#!/bin/bash
echo “$#; $0; $1; $2; $*; $@”
$ sparameters.sh arg1 arg2
2; ./sparameters.sh; arg1; arg2; arg1 arg2; arg1 arg2
Shell Parameters
Positional parameters
39. Shell Parameters
Positional parameters
$ vi trash.sh
#!/bin/bash
if [ $# -eq 1 ];
then
if [ ! –d “$HOME/trash” ];
then
mkdir “$HOME/trash”
fi
mv $1 “$HOME/trash”
else
echo “Use: $0 filename”
exit 1
fi