OpenShot 2.4.1 çıktı

GNU/Linux sistemler için Python, GTK ve MLT Framework ile yazılmış özgür bir video düzenleme yazılımı olan OpenShot 2.4.1 sürümüne güncellendi. Henüz resmi duyurusu yapılmamış olan sürüm, indirilmek üzere yansılarda yerini aldı. OpenShot Video Editor’un en yeni ve en mükemmel halinin kullanıma sunulduğu belirtilirken, son derece gelişmiş bir kararlılıkla gelen sürümde, geri alma/tekrarlama desteğinin geliştirildiği söyleniyor. Ayrıca, “yalnızca ses” ve “yalnızca Video” dışa aktarma seçeneklerinin eklendiği yazılımın, çevirileri de güncellenmiş bulunuyor.

Continue Reading →

OpenShot 2.4.0 edinmek için aşağıdaki linklerden yararlanabilirsiniz.

Resmi duyurusu yapıldıktan sonra;

0

Bash Scripting Part2 – For and While Loops With Examples

In the previous post, we talked about how to write a bash script, and we saw how bash scripting is awesome. In this post, we will look at the for command, while command, and how to make loops to iterate over a series of values. The for command enables you to perform a loop on a list of items. This is often the fundamental format of the for command.

 

Continue Reading →

for myvar in vars

do

Code Here

done

In every loop, the variable myvar holds one of the values of the list. The loop iterates until the list is finished.

Iterating Over Simple Values

You can iterate over simple values like this:

#!/bin/bash

for var in first second third fourth fifth

do

echo The $var item

done

Check the results:

bash scripting for loop

Iterating Over Complex Values

Your list maybe contains a comma or two words, and you want to deal with them as one item on the list.

Check the following example:

#!/bin/bash

for var in first "the second" "the third" "I’ll do it"

do

echo "This is: $var"

done

We quote our strings with double quotations.

We play nice till now, we always do. Just keep reading and practicing.

bash scripting compelx for loop

Command Substitution

By using command substitution using this format $(Linux command) you can store the result in a variable for later use.

#!/bin/bash

my_file="myfile"

for var in $(cat $my_file)

do

echo " $var"

done

Here we get the file content using cat command. Notice that our file contains one word per line, not separated by spaces.

bash scripting loop from command

Here we get the content of the file using command substitution then iterate over the result, assuming that each line has one word.

What about having spaces in one of these lines?

In this case, every word will be considered a field. You need to tell the shell to consider new lines as a separator instead of spaces.

The Field Separator

By default, the following characters treated as fields.

  • Space
  • Tab
  • newline

If your text includes any of these characters, the shell will assume it’s a new field.

Well, you can change the internal field separator or IFS environment variable. like this:

IFS=$'\n'

It will consider new lines as a separator instead of spaces.

#!/bin/bash

file="/etc/passwd"

IFS=$'\n'

for var in $(cat $file)

do

echo " $var"

done

You got it. Bash scripting is easy.

bash scripting passwd file

The separator is colons in /etc/passwd file which contains the user’s information, you can assign it like this:

IFS=:

Bash scripting is awesome, right?

Iterating Over Directory Files

If you want to list the files in /home directory, you can use the for loop like this:

#!/bin/bash

for obj in /home/likegeeks/*

do

if [ -d "$obj" ]

then

echo "$obj is a folder"

elif [ -f "$obj" ]

then

echo "$obj is a file"

fi

done

From the previous post, you should know the if statement and how to check for files and folders, so if you don’t know, I recommend you to review it bash script step by step.

bash scripting directory iteration

Here we use wildcard character which is the asterisk * and this is called in bash scripting file globbing which means All files with all names.

Notice that in the if statements here we quote our variables with quotations because maybe the file or the folder name contains spaces.

As you see the result, all files and directories in that folder are listed.

for Command C-Style

If you know C language, you may find that the for loop here is some weird because you are familiar with this syntax:

for (var= 0; var < 5; var++)

{

printf(“number is %d\n”, var);

}

Well, you can use the same syntax but with a little difference, here’s the syntax.

for (( variable = start ; condition ; iteration step))

So it looks like this:

for (( var = 1; var < 5; var++ ))

And this is an example:

#!/bin/bash

for (( var=1; var <= 10; var++ ))

do

echo "number is $var"

done

And this is the output:

bash scripting c-style

The while Command

The for loop is not the only way for looping in bash scripting. The while loop does the same job but it checks for a condition before every iteration.

The while loop command takes the following structure:

while condition

do

commands

done

and here is an example:

#!/bin/bash

number=10

while [ $number -gt 4 ]

do

echo $number

number=$[ $number - 1 ]

done

The script is simple; it starts with the while command to check if number is greater than zero, then the loop will run and the number value will be decreased every time by 1 and on every loop iteration it will print the value of number, Once the number value is zero the loop will exit.

bash scripting while loop

If we don’t decrease the value of var1, it will be the same value and the loop will be infinite.

Nesting Loops

You can type loops inside loops. This is called the nested loop.

Here’s an example of nested loops:

#!/bin/bash

for (( v1 = 1; v1 <= 5; v1++ ))

do

echo "Start $v1:"

for (( v2 = 1; v2 <= 5; v2++ ))

do

echo " Inner loop: $v2"

done

done

The outer loop hits first, then goes into the internal loop and completes it and go back to the outer loop and so on.

bash scripting nested loops

Iterate Over File Content

This is the most common usage for the for loop in bash scripting.

We can iterate over file content, for example, iterate over /etc/passwd file and see the output:

#!/bin/bash

IFS=$'\n'

for text in $(cat /etc/passwd)

do

echo "This line $text ++ contains"

IFS=:

for field in $text

do

echo " $field"

done

done

Here we have two loops, the first loop iterate over the lines of the file and the separator is the newline, the second iteration is over the words on the line itself and the separator is the colon :

bash scirpting file data

You can apply this idea when you have a CSV or any comma separated values file. The idea is the same; you just have to change the separator to fit your needs.

Controlling the Loop

Maybe after the loop starts you want to stop at a specific value, will you wait until the loop is finished? Of course no, there are two commands help us in this:

  • break command
  • continue command

The break Command

The break command is used to exit from any loop, like the while and the until loop

#!/bin/bash

for number in 10 11 12 13 14 15

do

if [ $number -eq 14 ]

then

break

fi

echo "Number: $number"

done

The loop runs until it reaches 14 then the break command exits the loop.

bash scirpting break command

And the same for the while loop:

#!/bin/bash

val=1

while [ $val -lt 5 ]

do

# Check number value

if [ $val -eq 4 ]

then

# The Code Breaks here <==

break

fi

# The Printed Message

echo "Iteration: $val"

val=$(( $val + 1 ))

done

The break command exits the while loop and that happens when the execution reaches the if statement.

bash scripting break while

The continue command

You can use the continue command to stop executing the remaining commands inside a loop without exiting the loop.

Check the following example:

#!/bin/bash

# The loop starts here

for (( number = 1; number < 10; number++ ))

do

# Check if number greater than 0 and less than 5

if [ $number -gt 0 ] && [ $number -lt 5 ]

then

continue

fi

# The printed message

echo "Iteration number: $number"

done

When the if condition is true, the continue command runs each iteration, and lines after the continue command never run until the condition becomes false.

bash scripting continue command

Redirecting the Loop Output

You can use the done command to send the loop output to a file like this:

#!/bin/bash

for (( var = 1; var < 10; var++ )) do echo "Number is $var" done > myfile.txt

echo "finished."#!/bin/bash

for (( var = 1; var < 10; var++ )) do echo "Number is $var" done > myfile.txt

echo "finished."

The shell creates the file myfile.txt and the output is redirected to the file, and if we check that file we will find our loop output inside it.

bash sciprintg process output

Let’s employ our bash scripting knowledge in something useful.

Useful Examples

Finding executables

To get all executable files on your system, you can iterate over the directories in the PATH variable. We discussed for loop and if statements and file separator so our toolset is ready. Let’s combine them together and make something useful.

#!/bin/bash

IFS=:

for dir in $PATH

do

echo "$dir:"

for myfile in $dir/*

do

if [ -x $myfile ]

then

echo " $myfile"

fi

done

done

This is just awesome. We were able to get all the executables on the system that we can run.

bash scripting finding executables

Now nothing stops you except your imagination.

I hope you learn a new thing or at least review your knowledge if you forget it. My last word for you, keep reading and practicing.

Thank you.

likegeeks.com

0

Lighttpd 1.4.48 duyuruldu

Açık kaynak kodlu, hızlı, güvenli, esnek ve uyumlu bir http sunucusu olan Lighttpd; 1.4.48 sürümüne güncellendi. Çeşitli hata düzeltmeleri gelen yeni sürümde, herhangi bir versiyonun en son kaynağını edinmek isteyenlerin, git deposundan faydalanabileceği ve bunun için bu sayfadan yararlanılabileceği ifade ediliyor. Sunucu için mükemmel bir çözüm olarak tarif edilen Lighttpd; yeniden düzenlenmiş BSD lisansı altında kullanılıyor. Düşük RAM kullanımı, etkin CPU kullanımı ve FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting gibi özellikleri ile özellikle yük sorunu olan sunucular için iyi bir çözüm olarak gösteriliyor. Tüm istekleri tek bir akış üzerinden alıp, aynı akış ile işleyip, geriye yine aynı yoldan verebilen bir sistem olduğu için, RAM kullanımında diğer alternatifleri Nginx ve Apache’den daha iyi bir kullanım sağlıyor. Ancak burada, CPU kullanımında Nginx’in Lighttpd’den daha iyi olduğunu hatırlatmak gerekir. Bu bakımdan Apache, PHP’yi fastCgi  olarak kullanmadığı her durumda hem işlemciyi hemde RAM’i aşırı tüketmek durumunda kalıyor. Nginx’in fastCgi ile PHP processlerini handle etmekte zorlandığı ve çözüm olarak da PhpFPM’in (Php fastCgi Process Management) önerildiği belirtiliyor. Lighttpd 1.4.48 hakkında ayrıntılı bilgi edinmek için sürüm duyurusunu inceleyebilirsiniz.

Continue Reading →

apachenginxlighttpd

Lighttpd 1.4.48 edinmek için aşağıdaki linkten yararlanabilirsiniz.

0

PHP 7.2.0 RC6 duyuruldu

PHP’nin çeşitli hataları giderilmiş bulunan 7.2.0 sürümünün altıncı sürüm adayı duyuruldu. PHP geliştirme ekibinin, PHP 7.2.0 RC6’yı duyurmaktan memnuniyet duyduğu belirtilirken, bunun 30 Kasım’da duyurulması planlanan final sürümden çok farklı bir versiyon olmadığı ifade edildi. Yeni özellikler, birkaç güvenlik hatasının giderimi ve diğer değişiklikler hakkında daha fazla bilgi edinmek için haberler veya yükseltme dosyalarının incelenebileceği söyleniyor. Bunun bir test sürümü olduğunun unutulmaması ve yalnızca test etmek amacıyla kullanılması gerektiği hatırlatılırken, test eden kullanıcıların tespit ettikleri hataları rapor etmeleri rica edildi. PHP 7.2.0 RC6 hakkında ayrıntılı bilgi edinmek için, PHP anasayfasından sürüm duyurusuna ulaşılabileceği belirtildi.

Continue Reading →

PHP 7.2.0 RC6 edinmek için aşağıdaki linkten yararlanabilirsiniz.

0

SharkLinux 4.13.0-17 duyuruldu

MATE masaüstü ortamıyla kullanıma sunulan Ubuntu tabanlı bir dağıtım olan SharkLinux‘un 4.13.0-17 sürümü duyuruldu. Güvenlik yamalarını çabucak uygulamak için paketlerin otomatik olarak yükseltildiği sistemde, kullanıcı kolaylığı için şifre gerektirmeden varsayılan olarak sudo erişimi sağlanıyor. Kimi sistem değişiklikleriyle gelen sürüm, sistem verimliliğini arttırmayı amaçlıyor. Paket yönetiminde değişiklikler ihtiva eden sürümde, daha önemli yükseltmelerin paket yönetiminde değişiklikler içerdiği söyleniyor. SharkLinux 4.13.0-17 hakkında ayrıntılı bilgi edinmek için sürüm duyurusunu inceleyebilirsiniz.

Continue Reading →

SharkLinux 4.13.0-17 edinmek için aşağıdaki linkten yararlanabilirsiniz.

0

Cinnamon 3.6.2 duyuruldu

Gelişmiş yenilikçi özellikler sunan, buna karşın, geleneksel kullanıcı deneyimini de bir biçimde sürdüren ve Linux Mint tarafından geliştirilen Cinnamon masaüstü ortamının 3.6.2 sürümü duyuruldu. Clement Lefebvre tarafından github.com üzerinden duyurulan yeni sürüm, böylelikle kullanıma sunulmuş oldu. Sürümün çıkarılmasına ilişkin olarak tüm ekip ve geliştiriciler adına duyulan mutluluk ifade edilirken, kullanıcıların çeşitli geliştirme ve yeniliklerle gelen sürümle ilgili olarak tespit ettikleri ayrıntıların geribildirimi konusunda tereddüt etmemeleri rica edildi. Cinnamon 3.6.2 hakkında ayrıntılı bilgi edinmek için değişiklikler sayfasını inceleyebilirsiniz.

Continue Reading →

Cinnamon 3.6.2 edinmek için aşağıdaki linkten yararlanabilirsiniz.

0

Bash Script Step By Step, You will love it

Today we are going to talk about bash scripting or shell scripting and how to write your first bash script. Actually, they are called shell scripts in general, but we are going to call them bash scripts because we are going to use bash among the other Linux shells. There are zsh, tcsh, ksh and other shells. In the previous posts, we saw how to use the bash shell and how to use Linux commands. The concept of a bash script is to run a series of Commands to get your job done. To run multiple commands in a single step from the shell, you can type them on one line and separate them with semicolons.

Continue Reading →

In the previous posts, we saw how to use the bash shell and how to use Linux commands.

The concept of a bash script is to run a series of Commands to get your job done.

To run multiple commands in a single step from the shell, you can type them on one line and separate them with semicolons.

pwd ; whoami

Actually, this is a bash script!!

The pwd command runs first, displaying the current working directory then the whoami command runs to show the currently logged in users.

You can run multiple commands as much as you wish, but with a limit. You can determine your max args using this command.

getconf ARG_MAX

Well, What about putting the commands into a file, and when we need to run these commands we run that file only. This is called a bash script.

First, make a new file using the touch command. At the beginning of any bash script, we should define which shell we will use because there are many shells on Linux, bash shell is one of them.

Bash Script Shebang

The first line you type when writing a bash script is the (#!) followed by the shell you will use.

#! <=== this sign is called shebang.

#!/bin/bash

If you use the pound sign (#) in front of any line in your bash script, this line will be commented which means it will not be processed, but, the above line is a special case . This line defines what shell we will use, which is bash shell in our case.

The shell commands are entered one per line like this:

#!/bin/bash

# This is a comment

pwd

whoami

You can type multiple commands on the same line but you must separate them with semicolons, but it is preferable to write commands on separate lines, this will make it simpler to read later.

Set Script Permission

After writing your bash script, save the file.

Now, set that file to be executable, otherwise, it will give you permissions denied. You can review how to set permissions using chmod command.

bash script permission

chmod +x ./myscript

Then try run it by just typing it in the shell:

./myscript

And Yes, it is executed.

bash script first run

Print Messages

As we know from other posts, printing text is done by echo command.

Edit our file and type this:

#!/bin/bash

# our comment is here

echo "The current directory is:"

pwd

echo "The user logged in is:"

whoami

Look at the output:

bash script echo command

Perfect! Now we can run commands and display text using echo command.

If you don’t know echo command or how to edit a file I recommend you to view previous articles about basic Linux commands

Using Variables

Variables allow you to store information to use it in your script.

You can define 2 types of variables in your bash script:

  • Environment variables
  • User variables

Environment Variables

Sometimes you need to interact with system variables, you can do this by using environment variables.

#!/bin/bash

# display user home

echo "Home for the current user is: $HOME"

Notice that we put the $HOME system variable between double quotations, and it prints the home variable correctly.

bash script global variables

What if we want to print the dollar sign itself?

echo "I have $1 in my pocket"

Because variable $1 doesn’t exist, it won’t work. So how to overcome that?

You can use the escape character which is the backslash \ before the dollar sign like this:

echo "I have \$1 in my pocket"

Now it works!!

bash script escape dollar sign

User Variables

Also, you can set and use your custom variables in the script.

You can call user variables in the same way like this:

#!/bin/bash

# User variables

grade=5

person="Adam"

echo "$person is a good boy, he is in grade $grade"

chmod +x myscript

./myscript

bash script user variables

Command Substitution

You can extract information from the result of a command using command substitution.

You can perform command substitution with one of the following methods:

  • The backtick character (`).
  • The $() format.

Make sure when you type backtick character, it is not the single quotation mark.

You must enclose the command with two backticks like this:

mydir=`pwd`

Or the other way:

mydir=$(pwd)

So the script could be like this:

#!/bin/bash

mydir=$(pwd)

echo $mydir

The output of the command will be stored in mydir variable.

bash script command substitution

Math calculation

You can perform basic math calculations using $(( 2 + 2 )) format:

#!/bin/bash

var1=$(( 5 + 5 ))

echo $var1

var2=$(( $var1 * 2 ))

echo $var2

Just that easy.

bash script math

if-then statement

You bash scripts will need conditional statements. Like if the value is smaller than 10 do this else do that. You can imagine any logic you want.

The most basic structure of if-then statement is like this:

if command

then

do something

fi

and here is an example:

#!/bin/bash

if whoami

then

echo "It works"

fi

Since the whoami command will return my user so the condition will return true and it will print the message.

Let’s dig deeper and use other commands we know.

Maybe searching for a specific user in the user’s file /etc/passwd and if a record exists, tell me that in a message.

#!/bin/bash

user=likegeeks

if grep $user /etc/passwd

then

echo "No such a user $user"

fi

bash script if-else

We use the grep command to search for the user in /etc/passwd file. You can check our tutorial about the grep command.

If the user exists, the bash script will print the message.

What if the user doesn’t exist? The script will exit the execution without telling us that the user doesn’t exist. OK, let’s improve the script more.

if-then-else Statement

The if-then-else statement takes the following structure:

if command

then

do something

else

do another thing

fi

If the first command runs and returns zero; which means success, it will not hit the commands after the else statement, otherwise, if the if statement returns non-zero; which means the statement condition fails, in this case, the shell will hit the commands after else statement.

#!/bin/bash

user=anotherUser

if grep $user /etc/passwd

then

echo "The user $user Exists"

else

echo "The user $user doesn’t exist"

fi

bash script if-else

We are doing good till now, keep moving.

Now, what if we need more else statements.

Well, that is easy, we can achieve that by nesting if statements like this:

if condition1

then

commands

elif condition2

then

commands

fi

If the first command return zero; means success, it will execute the commands after it, else if the second command return zero, it will execute the commands after it, else if none of these return zero, it will execute the last commands only.

#!/bin/bash

user=anotherUser

if grep $user /etc/passwd

then

echo "The user $user Exists"

elif ls /home

then

echo "The user doesn’t exist"

fi

You can imagine any scenario here, maybe if the user doesn’t exist, create a user using the useradd command or do anything else.

Numeric Comparisons

You can perform a numeric comparison between two numeric values using numeric comparison checks like this:

number1 -eq number2 Checks if number1 is equal to number2.

number1 -ge number2 Checks if number1 is bigger than or equal number2.

number1 -gt number2 Checks if number1 is bigger than number2.

number1 -le number2 Checks if number1 is smaller than or equal number2.

number1 -lt number2 Checks if number1 is smaller than number2.

number1 -ne number2 Checks if number1 is not equal to number2.

As an example, we will try one of them and the rest is the same.

Note that the comparison statement is in square brackets as shown.

#!/bin/bash

num=11

if [ $num -gt 10]

then

echo "$num is bigger than 10"

else

echo "$num is less than 10"

fi

bash script numeric compare

The num is greater than 10 so it will run the first statement and prints the first echo.

String Comparisons

You can compare strings with one of the following ways:

string1 = string2 Checks if string1 identical to string2.

string1 != string2 Checks if string1 is not identical to string2.

string1 < string2 Checks if string1 is less than string2.

string1 > string2 Checks if string1 is greater than string2.

-n string1 Checks if string1 longer than zero.

-z string1 Checks if string1 is zero length.

We can apply string comparison on our example:

#!/bin/bash

user ="likegeeks"

if [$user = $USER]

then

echo "The user $user is the current logged in user"

fi

bash script string compare

One tricky note about the greater than and less than for string comparisons, they MUST be escaped with the backslash because if you use the greater-than symbol only, it shows wrong results.

So you should do it like that:

#!/bin/bash

v1=text

v2="another text"

if [ $v1 \> "$v2" ]

then

echo "$v1 is greater than $v2"

else

echo "$v1 is less than $v2"

fi

bash script string greater than

It runs but it gives this warning:

./myscript: line 5: [: too many arguments

To fix it, wrap the $vals with a double quotation, forcing it to stay as one string like this:

#!/bin/bash

v1=text

v2="another text"

if [ $v1 \> "$v2" ]

then

echo "$v1 is greater than $v2"

else

echo "$v1 is less than $v2"

fi

bash script string fix

One important note about greater than and less than for string comparisons. Check the following example to understand the difference:

#!/bin/bash

v1=Likegeeks

v2=likegeeks

if [ $v1 \> $v2 ]

then

echo "$v1 is greater than $v2"

else

echo "$v1 is less than $v2"

fi

bash script character case

sort myfile

likegeeks

Likegeeks

bash script sort order

The test condition considers the lowercase letters bigger than capital letters. Unlike the sort command which does the opposite.

The test condition is based on the ASCII order, while the sort command is based on the numbering orders from the system settings.

File Comparisons

You can compare and check for files using the following operators:

-d my_file Checks if its a folder.

-e my_file Checks if the file is available.

-f my_file Checks if its a file.

-r my_file Checks if it’s readable.

my_file nt my_file2 Checks if my_file is newer than my_file2.

my_file ot my_file2 Checks if my_file is older than my_file2.

-O my_file Checks if the owner of the file and the logged user match.

-G my_file Checks if the file and the logged user have the idetical group.

As they imply, you will never forget them.

Let’s pick one of them and take it as an example:

#!/bin/bash

mydir=/home/likegeeks

if [ -d $mydir ]

then

echo "Directory $mydir exists"

cd $mydir

ls

else

echo "NO such file or directory $mydir"

fi

bash script file checking

We are not going to type every one of them as an example. You just type the comparison between the square brackets as it is and complete you script normally.

There are some other advanced if-then features but let’s make it in another post.

That’s for now. I hope you enjoy it and keep practicing more and more.

Thank you.

likegeeks.com

0