Setting option flags -n -v -x
sh -n scriptname checks for syntax errors without actually running the script. This is the equivalent of inserting set -n or set -o noexec into the script. Note that certain types of syntax errors can slip past this check.
sh -v scriptname echoes each command before executing it. This is the equivalent of inserting set -v or set -o verbose in the script.
The -n and -v flags work well together. sh -nv scriptname gives a verbose syntax check.
sh -x scriptname echoes the result each command, but in an abbreviated manner. This is the equivalent of inserting set -x or set -o xtrace in the script.
Inserting set -u or set -o nounset in the script runs it, but gives an unbound variable error
message and aborts the script.
2012年6月26日星期二
2012年6月25日星期一
Playing music
#!/bin/bash
# music.sh
# MUSIC WITHOUT EXTERNAL FILES
# Author: Antonio Macchi
# Used in ABS Guide with permission
# /dev/dsp default = 8000 frames per second, 8 bits per frame (1 byte),
#+ 1 channel (mono)
duration=2000 # If 8000 bytes = 1 second, then 2000 = 1/4 second.
volume=$'\xc0' # Max volume = \xff (or \x00).
mute=$'\x80' # No volume = \x80 (the middle).
function mknote () # $1=Note Hz in bytes (e.g. A = 440Hz ::
{ #+ 8000 fps / 440 = 16 :: A = 16 bytes per second)
for t in `seq 0 $duration`
do
test $(( $t % $1 )) = 0 && echo -n $volume || echo -n $mute
done
}
e=`mknote 49`
g=`mknote 41`
a=`mknote 36`
b=`mknote 32`
c=`mknote 30`
cis=`mknote 29`
d=`mknote 27`
e2=`mknote 24`
n=`mknote 32767`
# European notation.
echo -n "$g$e2$d$c$d$c$a$g$n$g$e$n$g$e2$d$c$c$b$c$cis$n$cis$d \
$n$g$e2$d$c$d$c$a$g$n$g$e$n$g$a$d$c$b$a$b$c" > /dev/dsp
# dsp = Digital Signal Processor
exit # A "bonny" example of a shell script!
# music.sh
# MUSIC WITHOUT EXTERNAL FILES
# Author: Antonio Macchi
# Used in ABS Guide with permission
# /dev/dsp default = 8000 frames per second, 8 bits per frame (1 byte),
#+ 1 channel (mono)
duration=2000 # If 8000 bytes = 1 second, then 2000 = 1/4 second.
volume=$'\xc0' # Max volume = \xff (or \x00).
mute=$'\x80' # No volume = \x80 (the middle).
function mknote () # $1=Note Hz in bytes (e.g. A = 440Hz ::
{ #+ 8000 fps / 440 = 16 :: A = 16 bytes per second)
for t in `seq 0 $duration`
do
test $(( $t % $1 )) = 0 && echo -n $volume || echo -n $mute
done
}
e=`mknote 49`
g=`mknote 41`
a=`mknote 36`
b=`mknote 32`
c=`mknote 30`
cis=`mknote 29`
d=`mknote 27`
e2=`mknote 24`
n=`mknote 32767`
# European notation.
echo -n "$g$e2$d$c$d$c$a$g$n$g$e$n$g$e2$d$c$c$b$c$cis$n$cis$d \
$n$g$e2$d$c$d$c$a$g$n$g$e$n$g$a$d$c$b$a$b$c" > /dev/dsp
# dsp = Digital Signal Processor
exit # A "bonny" example of a shell script!
Checking whether a disk is in the CD-burner (soft-linked to /dev/hdc):
head -1 /dev/hdc
# head: cannot open '/dev/hdc' for reading: No medium found
# (No disc in the drive.)
# head: error reading '/dev/hdc': Input/output error
# (There is a disk in the drive, but it can't be read;
#+ possibly it's an unrecorded CDR blank.)
# Stream of characters and assorted gibberish
# (There is a pre-recorded disk in the drive,
#+ and this is raw output -- a stream of ASCII and binary data.)
# Here we see the wisdom of using 'head' to limit the output
#+ to manageable proportions, rather than 'cat' or something similar.
# head: cannot open '/dev/hdc' for reading: No medium found
# (No disc in the drive.)
# head: error reading '/dev/hdc': Input/output error
# (There is a disk in the drive, but it can't be read;
#+ possibly it's an unrecorded CDR blank.)
# Stream of characters and assorted gibberish
# (There is a pre-recorded disk in the drive,
#+ and this is raw output -- a stream of ASCII and binary data.)
# Here we see the wisdom of using 'head' to limit the output
#+ to manageable proportions, rather than 'cat' or something similar.
why is it called "loopback" device?
from http://stackoverflow.com/questions/3614719/what-does-loop-mean-in-loop-device
------------------------
------------------------
Why
is it called "loopback" though? I can see two parallels: Loopback of
the network device (i.e having some word play), or loop back in the
sense that the driver asks back into the file-system again for the file
to map into. What meaning is correct? – Johannes Schaub - litb Sep 1 '10 at 4:02
3 |
It's the latter one. Normally a request would go
userspace -> VFS -> block device layer
, but when the block device driver is loop, it goes userspace -> VFS -> loop device -> VFS -> block device
. So it loops back to a higher level. – hobbs Sep 1 '10 at 4:19
As far
as I know the term originated in the depths of the telecom industry (and
probably dates back to telegraphs). See mmonem's answer. – RBerteig Sep 1 '10 at 6:44
---------------------------
I guess this term comes from the communication
realm when sometimes it is needed to test the communication system by
simulating a peer using a proxy circuit loop.
The concept came also to UNIX networking where loopback network interfaces do not send network traffic to the medium.
The same concept in file systems loop means that the file system driver does not really goes through the hard disk IO stack and, instead, ends using a plain disk image file for IO.
The concept came also to UNIX networking where loopback network interfaces do not send network traffic to the medium.
The same concept in file systems loop means that the file system driver does not really goes through the hard disk IO stack and, instead, ends using a plain disk image file for IO.
----------------------------------
2012年6月12日星期二
strdup.c
char *strdup (const char *s) {
char *d = malloc (strlen (s) + 1); // Space for length plus nul
if (d == NULL) return NULL; // No memory
strcpy (d,s); // Copy the characters
return d; // Return the new string
}
how to activate root account in imac
zz-http://www.ylmf.net/mac/tips/2010120112477.html
su passwd root好用
Root user,又名超级用户,是一个权力最高的Unix 账户,Root 的账户能在整个系统里任何部份进行任何“操作”,包括:拷贝档案、移动/移除档案、执行程序等。所以,通常 Root 的账户都只会指派给高级专业的用户使用。因此,苹果把Root user 隐藏在Mac OS X 里。
但有时候我们不得不启用Root用户以便于实现某些操作,可以通过以下三种方法把启动Root账户。
方法一:
把Mac OS X 的安装光盘放入到光驱中,用光盘启动系统,在安装菜单里选择“Password Reset”选项,便能更改你的密码和启动超级用户模式。(把这工具拷贝到硬盘中是不能启动的,一定要从光盘启动才有效。)
方法二:
在Mac OS X里启动Terminal(在“应用程序/实用工具”的文件夹中),输入以下命令:
sudo passwd Root
系统会实时要求输入 Root user的新密码,然后再输入一次,以确保密码正确。
方法三:
启动NetInfo Manager应用程序(在“应用程序/实用工具”的文件夹中),再依照以 下步骤:
1. 从菜单中选择“域”→“用户”→“启动Root用户”
2. 点按窗口底部的“锁状”按钮,然后输入在安装过程中提供的用户名称和密码注册。
3. 从窗口下半部份的列表中选择 * 号一栏,再输入 Root user 已加密的新密码。
可在 Terminal 里输入以下的「htpasswd」命令来产生加密的新密码:
[localhost:~] currentuser% htpasswd -nb anylogin yourpassword
[return]
[localhost:~] currentuser% anylogin : pu9fQgdzVHRB2
pu9fQgdzVHRB2 就是已加密的新密码
4. 点按窗口底部的“锁状”按钮,然后储存更改和离开 NetInfo Manager。
现在可以在 Terminal 里试试 Root user 的新密码
su passwd root好用
Root user,又名超级用户,是一个权力最高的Unix 账户,Root 的账户能在整个系统里任何部份进行任何“操作”,包括:拷贝档案、移动/移除档案、执行程序等。所以,通常 Root 的账户都只会指派给高级专业的用户使用。因此,苹果把Root user 隐藏在Mac OS X 里。
但有时候我们不得不启用Root用户以便于实现某些操作,可以通过以下三种方法把启动Root账户。
方法一:
把Mac OS X 的安装光盘放入到光驱中,用光盘启动系统,在安装菜单里选择“Password Reset”选项,便能更改你的密码和启动超级用户模式。(把这工具拷贝到硬盘中是不能启动的,一定要从光盘启动才有效。)
方法二:
在Mac OS X里启动Terminal(在“应用程序/实用工具”的文件夹中),输入以下命令:
sudo passwd Root
系统会实时要求输入 Root user的新密码,然后再输入一次,以确保密码正确。
方法三:
启动NetInfo Manager应用程序(在“应用程序/实用工具”的文件夹中),再依照以 下步骤:
1. 从菜单中选择“域”→“用户”→“启动Root用户”
2. 点按窗口底部的“锁状”按钮,然后输入在安装过程中提供的用户名称和密码注册。
3. 从窗口下半部份的列表中选择 * 号一栏,再输入 Root user 已加密的新密码。
可在 Terminal 里输入以下的「htpasswd」命令来产生加密的新密码:
[localhost:~] currentuser% htpasswd -nb anylogin yourpassword
[return]
[localhost:~] currentuser% anylogin : pu9fQgdzVHRB2
pu9fQgdzVHRB2 就是已加密的新密码
4. 点按窗口底部的“锁状”按钮,然后储存更改和离开 NetInfo Manager。
现在可以在 Terminal 里试试 Root user 的新密码
how to solve mkdir permission issue in imac
ZZ-http://myth326.blog.163.com/blog/static/122251863201122410491446/
Well, Apple doesn't want you to (with good reason, automounter owns this dir, which makes it easier to do NFS mounts and such) so you shouldn't muck with it but if you really just 'have to do it', here is how you can.
Basically:
example:
before:
NOTE: I wouldn't do anything 'important' with this directory as it's easy to forget you altered this and an upgrade will plow over this directory, removing all data. (this dir is also not included in any Time Machine backups.
official solution- http://support.apple.com/kb/TS3346?viewlocale=zh_CN
Mac OS X mkdir: /home/test: Operation not supported
Hmmm, trying to create a directory under '/home' on a Mac?
Well, Apple doesn't want you to (with good reason, automounter owns this dir, which makes it easier to do NFS mounts and such) so you shouldn't muck with it but if you really just 'have to do it', here is how you can.
Basically:
Edit /etc/auto_master and remove or comment out the line that starts with "/home".
example:
sudo vim /etc/auto_master
before:
# Automounter master map +auto_master # Use directory service /net -hosts -nobrowse,hidefromfinder,nosuid /home auto_home -nobrowse,hidefromfinder /Network/Servers -fstab /- -staticafter:
# Automounter master map +auto_master # Use directory service /net -hosts -nobrowse,hidefromfinder,nosuid #/home auto_home -nobrowse,hidefromfinder /Network/Servers -fstab /- -staticto have the change take effect without a reboot:
sudo automount
mkdir /home/test
ls -l /home/
total 0
drwxr-xr-x 3 root admin 102 Aug 10 11:33 test
NOTE: I wouldn't do anything 'important' with this directory as it's easy to forget you altered this and an upgrade will plow over this directory, removing all data. (this dir is also not included in any Time Machine backups.
official solution- http://support.apple.com/kb/TS3346?viewlocale=zh_CN
Mac OS X v10.6:后续 Active Directory 用户收到警告“此时您无法登录到用户账户(用户名)”
受影响的产品
Mac OS X 10.5, Mac OS X 10.6问题的表现
Active Directory 用户在尝试登录时,可能会收到消息“此时您无法登录到用户账户(用户名)”。在同一台服务器的不同共享点上具有个人目录的后续 Active Directory 用户可能会遇到此问题。如果 Mac OS X 客户端重新启动则可登录。解决
编辑受影响 Mac OS X 用户的 /etc/auto_master 文件。如下所示对 /Network/Servers 目录做出标注:# Automounter master map # +auto_master # Use directory service /net -hosts -nobrowse,hidefromfinder,nosuid /home auto_home -nobrowse,hidefromfinder #/Network/Servers -fstab /- -static保存文件,然后重新启动。
订阅:
博文 (Atom)