Linux shell 脚本不会按预期更改为目录/子目录



我试图构建一个shell脚本来设置Django目录结构。我对PC/DOS批处理语言相当了解,我正在尝试完成目录结构设置。

我想帮助我的sh脚本更改/创建目录和运行命令…

然而…当我在下面运行脚本时,我得到了一个错误…

$ sh setup .sh proj222 app222

mkdir $1
cd $1
python3 -m venv venv$1
source venv$1/bin/activate
pip install django && pip install django-oso && pip install django-debug-toolbar && sudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib && pip install Django psycopg2 && python3 -m pip install Pillow
django-admin startproject config .
mkdir apps
mkdir templates
mkdir tests
mkdir utils
cd apps
ls
django-admin startapp $2
ls
cd $2
touch urls.py
ls
# cd ..
python3 manage.py migrate
python3 manage.py runserver

没有这样的文件或目录

thalacker@HPLaptop17Linux:~/codeplatoon/djangoProjects$ sh setup3.sh proj222 app222
setup3.sh: 28: source: not found
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: django in /home/thalacker/.local/lib/python3.10/site-packages (4.1.1)
Requirement already satisfied: asgiref<4,>=3.5.2 in /home/thalacker/.local/lib/python3.10/site-packages (from django) (3.5.2)
Requirement already satisfied: sqlparse>=0.2.2 in /home/thalacker/.local/lib/python3.10/site-packages (from django) (0.4.2)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: django-oso in /home/thalacker/.local/lib/python3.10/site-packages (0.26.2)
Requirement already satisfied: oso~=0.26.2 in /home/thalacker/.local/lib/python3.10/site-packages (from django-oso) (0.26.3)
Requirement already satisfied: django>=2.2 in /home/thalacker/.local/lib/python3.10/site-packages (from django-oso) (4.1.1)
Requirement already satisfied: sqlparse>=0.2.2 in /home/thalacker/.local/lib/python3.10/site-packages (from django>=2.2->django-oso) (0.4.2)
Requirement already satisfied: asgiref<4,>=3.5.2 in /home/thalacker/.local/lib/python3.10/site-packages (from django>=2.2->django-oso) (3.5.2)
Requirement already satisfied: cffi~=1.15 in /home/thalacker/.local/lib/python3.10/site-packages (from oso~=0.26.2->django-oso) (1.15.1)
Requirement already satisfied: pycparser in /home/thalacker/.local/lib/python3.10/site-packages (from cffi~=1.15->oso~=0.26.2->django-oso) (2.21)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: django-debug-toolbar in /usr/local/lib/python3.10/dist-packages (3.7.0)
Requirement already satisfied: sqlparse>=0.2.0 in /home/thalacker/.local/lib/python3.10/site-packages (from django-debug-toolbar) (0.4.2)
Requirement already satisfied: Django>=3.2.4 in /home/thalacker/.local/lib/python3.10/site-packages (from django-debug-toolbar) (4.1.1)
Requirement already satisfied: asgiref<4,>=3.5.2 in /home/thalacker/.local/lib/python3.10/site-packages (from Django>=3.2.4->django-debug-toolbar) (3.5.2)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-pip is already the newest version (22.0.2+dfsg-1).
python3-dev is already the newest version (3.10.6-1~22.04).
libpq-dev is already the newest version (15.1-1.pgdg22.04+1).
postgresql is already the newest version (15+246.pgdg22.04+1).
postgresql-contrib is already the newest version (15+246.pgdg22.04+1).
0 upgraded, 0 newly installed, 0 to remove and 53 not upgraded.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: Django in /home/thalacker/.local/lib/python3.10/site-packages (4.1.1)
Requirement already satisfied: psycopg2 in /usr/local/lib/python3.10/dist-packages (2.9.5)
Requirement already satisfied: asgiref<4,>=3.5.2 in /home/thalacker/.local/lib/python3.10/site-packages (from Django) (3.5.2)
Requirement already satisfied: sqlparse>=0.2.2 in /home/thalacker/.local/lib/python3.10/site-packages (from Django) (0.4.2)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (9.0.1)
app222
admin.py  apps.py  __init__.py  migrations  models.py  tests.py  urls.py  views.py
python3: can't open file '/home/thalacker/codeplatoon/djangoProjects/proj222/apps/app222/manage.py': [Errno 2] No such file or directory
python3: can't open file '/home/thalacker/codeplatoon/djangoProjects/proj222/apps/app222/manage.py': [Errno 2] No such file or directory

尝试将#!/bin/bash放在setup3.sh的第一行

相关内容

  • 没有找到相关文章

最新更新