linux poison RSS
linux poison Email
0

Bash Script: Create & Use Associative Array like Hash tables

Before using Associative Array features make sure you have bash version 4 and above, use command "bash --version" to know your bash version.

Below shell script demonstrate  the usage of associative arrays, feel free to copy and use this code.

Associative arrays are created using declare -A name

Source: cat associative_array.sh
#!/bin/bash

# use -A option declares associative array
declare -A array

# Here, you can have some other process to fill up your associative array.
array[192.168.1.1]="host1"
array[192.168.1.2]="host2"
array[192.168.1.3]="host3"
array[192.168.1.4]="host4"
array[192.168.1.5]="host5"

echo -n "Enter the ip address to know the hostname: "
read ipaddress

# Now you can use the associative array as hash table, (key,value) pairs.
echo "Hostname associated with the $ipaddress is: ${array[$ipaddress]}"

# You can also perform all the basic array operation.
# Iterate over Associative Arrays

#for hostname in "${array[@]}"; do
#       echo $hostname
#done


Output: ./associative_array.sh 
Enter the ip address to know the hostname: 192.168.1.4
Hostname associated with the 192.168.1.4 is: host4


Read more
2

Cross-platform and easy to use Audio Editor - ocenaudio

Ocenaudio is a cross-platform, easy to use, fast and functional audio editor. It is the ideal software for people who need to edit and analyze audio files without complications. ocenaudio also has powerful features that will please more advanced users.

This software is based on Ocen Framework, a powerful library developed to simplify and standardize the development of audio manipulation and analysis applications across multiple platforms.

Features for Ocenaudio:
 * VST plugins support
 * Preview effects in Real-time
 * Drag & Drop support
 * Various effect options (silence, reverse, invert, delay, etc.)
 * Multi-selection support
 * Large file editing support
 * Fully-featured spectrogram

Read more
0

Single application to convert Audio, Video, Image and Document files to other formats

FF Multi Converter is a simple graphical application which enables you to convert audio, video, image and document files between all popular formats, using and combining other programs.

It uses ffmpeg for audio/video files, unoconv for document files and PythonMagick library for image file conversions. Common conversion options for each file type are provided. Audio/video ffmpeg-presets management and recursive conversion options are available too.

FF Multi Converter Features
 * Conversions for several file formats.
 * Very easy to use interface.
 * Access to common conversion options.
 * Audio/video ffmpeg-presets management.
 * Options for saving and naming files.
 * Recursive conversions.

Read more
0

Bash Script: Difference betweem single ( ' ) and double quotes ( " )

The Bash manual has this to say:

Single Quotes
Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

Double Quotes
Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’. The characters ‘$’ and ‘`’ retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The backslash preceding the ‘!’ is not removed.

The special parameters ‘*’ and ‘@’ have special meaning when in double quotes (see Shell Parameter Expansion).

Read more
0

Bash script: Using shift statement to loop through command line arguments

A shift statement is typically used when the number of arguments to a command is not known in advance and it takes a number (N), in  which the positional parameters are shifted to the left by this number, N.

Say you have a command that takes 10 arguments, and N is 4, then $4 becomes $1, $5 becomes $2 and so on. $10 becomes $7 and the original $1, $2 and $3 are thrown away.

Below is the simple example showing the usage of 'shift' statements:

Source:  cat shift2.sh
#!/bin/bash

echo "Total number of arg passed: $#"
echo "arg values are: $@"
echo "-----------------------------------------"

while [[ $# > 0 ]] ; do
        echo "\$1 = $1"
        shift
done

echo

Output: ./shift2.sh a b c d e f
Total number of arg passed: 6
arg values are: a b c d e f
-----------------------------------------
$1 = a
$1 = b
$1 = c
$1 = d
$1 = e
$1 = f




Read more
Related Posts with Thumbnails