Skip to content

Instantly share code, notes, and snippets.

@tianweidut
Created July 17, 2015 06:31
Show Gist options
  • Select an option

  • Save tianweidut/1c276faaa85c3433c29a to your computer and use it in GitHub Desktop.

Select an option

Save tianweidut/1c276faaa85c3433c29a to your computer and use it in GitHub Desktop.
shell 技巧: 1. exec 一个shell func: export -f func_name; exec bash -c “func_name” 2. 判断命令输出是否为空 if [[ -n $(docker ps -f name=test)]]; 3. 判断命令的返回码是否为0(即是否正确执行exit 0) if docker ps ;
#!/bin/sh
ulimit -n 65536
exec 2>&1
create_container () {
echo 'try to create container'
sudo docker create --name 'gentoo_with_portage' \
-v /usr/portage/ \
-v /var/lib/layman/ \
-v /var/cache/edb/ \
-v /etc/portage/package.keywords/ \
-v /etc/portage/package.mask/ \
-v /etc/portage/package.unmask/ \
docker-registry.intra.douban.com/gentoo_with_portage:latest true
echo 'finish create container'
}
check_container () {
while true; do
if [[ -n $(sudo docker ps -q -a -f name='gentoo_with_portage') ]] ; then
echo 'container exists, continue...'
sleep 5
else
echo 'no gentoo_with_portage container, will exit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment