This commit is contained in:
Yavuz Sava 2025-02-02 19:23:09 +03:00
parent 6f815683cd
commit 47c49e7362

View File

@ -358,6 +358,94 @@
" echo \"Retry #$n\"\n",
"done;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## For loops in bash scripts"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/bin/bash\n",
"for file in *.HTM; do\n",
" name=$(basename \"$file\" .HTM)\n",
" mv \"$file\" \"$name.html\" \n",
"done"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/bin/bash\n",
"for file in *.HTM; do\n",
" name=$(basename \"$file\" .HTM)\n",
" echo mv \"$file\" \"$name.html\" \n",
"done"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Advanced Command Interaction"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tail /var/log/syslog | cut -d' ' -f5-"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cut -d' ' -f5- /var/log/syslog | sort | uniq -c | sort -nr | head"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/bin/bash\n",
"\n",
"for logfile in /var/log/*log; do\n",
" echo \"Processing: $logfile\"\n",
" cut -d' ' -f5- $logfile | sort | uniq -c | sort -nr | head -5\n",
"done"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Choosing between Bash and Python"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for i in $(cat story.txt); do B=`echo -n \"${i:0:1}\" | tr \"[:lower:]\" \"[:upper:]\"`; echo -n \"${B}${i:1} \"; done; echo -e \"\\n\""
]
}
],
"metadata": {