Linux and C Practical Guide
Linux and C Practical Guide
Guide (Simplified)
Simple Shell Script for Cloud Shell
This script will:
- Use basic variables
- Check file and string conditions
- Perform simple control structures (if-else, loops)
- Use positional parameters
- Include a simple function
str1="hello"
str2="Hello"
if [ "$str1" = "$str2" ]; then
echo "The strings are the same."
else
echo "The strings are different."
fi
my_function() {
echo "This is a simple function!"
}
my_function
C Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
char myVar[] = "C programming in action!";
printf("Variable content: %s\n", myVar);
int number;
printf("Enter a number: ");
scanf("%d", &number);
if (number > 0) {
printf("The number is positive.\n");
} else if (number < 0) {
printf("The number is negative.\n");
} else {
printf("The number is zero.\n");
}
if (strcmp(str1, str2) == 0) {
printf("The strings are the same.\n");
} else {
printf("The strings are different.\n");
}
char filename[100];
printf("Enter a file name to check: ");
scanf("%s", filename);
if (fileExists(filename)) {
printf("File exists.\n");
} else {
printf("File does not exist.\n");
}
printf("Calling a function:\n");
printf("This is a simple function demonstration!\n");
return 0;
}