Tareas De Astereo

Páginas: 2 (467 palabras) Publicado: 21 de junio de 2012
EJEMPLOS EN ARREGLOS EN LINUX

¿Como declarar un arreglo en Linux?
declare -a arrayname=(element1 element2 element3)
nombre del arreglo, asignarle elementos entre paréntesis

#! /bin/bash
$catarraymanip.sh
declare -a Unix=('Debian' 'Red hat' 'Red hat' 'Suse' 'Fedora');

1.-$ cat arraymanip.sh
#! /bin/bash
Unix[0]='Debian'
Unix[1]='Red hat'
Unix[2]='Ubuntu'
Unix[3]='Suse'
echo${Unix[1]}
$./arraymanip.sh
Red hat
2.-$ cat arraymanip.sh
declare -a Unix=('Debian' 'Red hat' 'Suse' 'Fedora');
echo ${#Unix[@]} #Number of elements in the array
echo ${#Unix} #Number ofcharacters in the first element of the array.i.e Debian
$./arraymanip.sh
4
6

3.- $cat arraymanip.sh
#! /bin/bash
Unix[0]='Debian'
Unix[1]='Red hat'
Unix[2]='Ubuntu'
Unix[3]='Suse'
echo${#Unix[3]} # length of the element located at index 3 i.e Suse
$./arraymanip.sh
4

4.- $cat arraymanip.sh
Unix=('Debian' 'Red hat' 'Ubuntu' 'Suse' 'Fedora' 'UTS' 'OpenLinux');
echo ${Unix[@]:3:2}$./arraymanip.sh
Suse Fedora

5.- $cat arraymanip.sh
#! /bin/bash
Unix=('Debian' 'Red hat' 'Ubuntu' 'Suse' 'Fedora' 'UTS' 'OpenLinux');
echo ${Unix[2]:0:4}
./arraymanip.sh
Ubun

6.-$cat arraymanip.sh
#!/bin/bash
Unix=('Debian' 'Red hat' 'Ubuntu' 'Suse' 'Fedora' 'UTS' 'OpenLinux');
echo ${Unix[@]/Ubuntu/SCO Unix}
$./arraymanip.sh
Debian Red hat SCO Unix Suse Fedora UTSOpenLinux

7.- $cat arraymanip.sh
Unix=('Debian' 'Red hat' 'Ubuntu' 'Suse' 'Fedora' 'UTS' 'OpenLinux');
Unix=("${Unix[@]}" "AIX" "HP-UX")
echo ${Unix[7]}
$./arraymanip.sh
AIX

8.- $catarraymanip.sh
#!/bin/bash
Unix=('Debian' 'Red hat' 'Ubuntu' 'Suse' 'Fedora' 'UTS' 'OpenLinux');
unset Unix[3]
echo ${Unix[3]}

$ cat arraymanip.sh
Unix=('Debian' 'Red hat' 'Ubuntu' 'Suse''Fedora' 'UTS' 'OpenLinux');
pos=3
Unix=(${Unix[@]:0:$pos} ${Unix[@]:$(($pos + 1))})
echo ${Unix[@]}
$./arraymanip.sh
Debian Red hat Ubuntu Fedora UTS OpenLinux

9.- $ cat arraymanip.sh...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • tares tares tares
  • Tareas tareas y mas tareas
  • tareas tareas
  • Taran Taran
  • tareas tareas
  • Tareas Y Tareas
  • Mis tareas...Tus tareas
  • Tareas de Tareas

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS