-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntroduction-Bash
47 lines (30 loc) · 2.3 KB
/
Introduction-Bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
1. Variable and assigning value must be space less otherwise it would be the part of either variable or value and this thing is detected and gives as an error by bash .
Token="dsfnjls-sdfdf-sdfsf"
2. In curl command when we send content as is in text form it would give error because of some special charaters , for solving this problem we have to options
1. base64 : $(cat $file | base64 --wrap 0)
2. urlencode :
curl --request POST --header "PRIVATE-TOKEN: ${Token}" --header "Content-Type: application/x-www-form-urlencoded" "https://${Gitlab_host}/api/v4/projects/${Project_id}/repository/files/app7%2F${filename}?branch=main&commit_message=doit" --data-urlencode "content=$(cat $file)"
3. $(cat $file) , $(>$file) ,ls
4. Parameter given is called by using as $1,$2,$3
5.
curl sends errors to STDERR and will not get captured by $m. The output of curl is sent to STDERR (that gibberish you mentioned).
One solution is to redirect STDERR to STDOUT by adding 2>&1 to your curl invocation in your script:
m=$(curl -u "$user":AP"$pass" -T "$pathA" "$url" 2>&1)
if [ $? -ne 0 ] ; then
echo "Error: ""$m"
fi
You could also use the --fail, --silent and --show-errors flags of curl like in this example if all you care about are the errors:
Making curl send errors to stderr and everything else to stdout
and some information about capturing STDERR to $variable in bash scripts:
Bash how do you capture stderr to a variable?.
6. Shabang #!bin/bash It is special statement which fetch the all declarations of features supported by bash. helped a lot!
7. +,%20 both can be used as query characters inside the curl statement.
$( curl --silent --request PUT --header "PRIVATE-TOKEN: ${token}" "https://${gitlabHost}/api/v4/projects/${projectId}/
merge_requests/${mergeRequestID}/merge?should_remove_source_branch=true&squash=true
&squash_commit_message=Moving+upgrade+data+files+for+release+${releaseTag}" --data "merge_commit_message=Moving+upgrade+data+files")
8. In Curl Api
1.encoding decoding feature
2.paging feature page=2&per_page=20
3. url-encoding because it is user-friendly.
https://git.hotwax.co/api/v4/projects/161/repository/tags?order_by=name&sort=desc&search=^v3.&page=2&per_page=20
9. Newline "\n" is encoded as "%0D%0A" in query string values