Configuring Shell Environment Variables: Understanding Dynamic Variable Decoupling

demonstrate the ability to configure shell n.w
1 / 40
Embed
Share

Learn how to configure shell environment variables with dynamic values that can impact running processes. Explore the concept of decoupling configuration from the program for better flexibility and control. Dive into the significance of command line parameters and compilation processes in Java programming.

  • Shell
  • Environment Variables
  • Dynamic Values
  • Decoupling
  • Compilation

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Demonstrate the ability to configure shell environment variables

  2. some attempts at defining environment variable a dynamic-named value that can affect a running process a dynamic "object" on a computer, containing an editable value a part of the environment in which a process runs a variable where the value is set outside a way to decouple configuration from the program (what does that mean?) to start with, they are just string variables it is mostly about the decoupling

  3. why do we have/use command line parameters? a program to get the first assignment from a web server using htt protocol: (you would normally use a browser, and it would do this for you) class GetAsn1Itec252 { public static void main(String[] ags) { try { String str=null; Socket s = new Socket( 147.182.177.199 , 80); BufferedReader br = new BufferedReader (new InputStreamReader(s.getInputStream())); BufferedWriter bw = new BufferedWriter (new OutputStreamWriter(s.getOutputStream())); while ((str = br.readLine()) != null) System.out.printf("%s\n", str); bw.write( GET /cs252.a1.html HTTP/1.1 , 0, 27); bw.newLine(); bw.newLine(); bw.flush(); }catch (Exception e) { e.printStackTrace(); } } }

  4. compile it: $ javac GetAsn1Itec252.java run it: $ java GetAsn1Itec252 //really we are running the program java now, every time you want to get a copy of the first assignment, you can run this program, for the second assignment, I will edit the source code to change the file name, then compile it to make a new program: GetAsn2Itec252.java The act of compiling here is not too terribly complicated, but it does require: understanding the concept being able to create new files being able to change the code with a text editor or ide having the java compiler software (in the jdk)

  5. for more complicated programs however compiling them can be quite involved it can even be the main focus of a person s job the build engineer therefore, compiling is not left to up to the customer once the binary is delivered, it can t be recompiled on site binary changes have to come from the company that built the software

  6. A tiny bit (<1%) of the output from compiling openssl SM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM -DSHA256_ASM - DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" - DENGINESDIR="\"/usr/local/lib/engines-3\"" -DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/dsa/libfips-lib-dsa_key.d.tmp -MT crypto/dsa/libfips-lib-dsa_key.o -c -o crypto/dsa/libfips-lib-dsa_key.o crypto/dsa/dsa_key.c gcc -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM -DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM - DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC - pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-3\"" - DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/dsa/libfips-lib-dsa_lib.d.tmp -MT crypto/dsa/libfips-lib-dsa_lib.o -c -o crypto/dsa/libfips-lib-dsa_lib.o crypto/dsa/dsa_lib.c gcc -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM -DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM - DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC - pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-3\"" - DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/dsa/libfips-lib-dsa_ossl.d.tmp -MT crypto/dsa/libfips-lib-dsa_ossl.o -c -o crypto/dsa/libfips-lib-dsa_ossl.o crypto/dsa/dsa_ossl.c gcc -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM -DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM - DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC - pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-3\"" - DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/dsa/libfips-lib-dsa_sign.d.tmp -MT crypto/dsa/libfips-lib-dsa_sign.o -c -o crypto/dsa/libfips-lib-dsa_sign.o crypto/dsa/dsa_sign.c gcc -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM -DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM - DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC - pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-3\"" - DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/dsa/libfips-lib-dsa_vrf.d.tmp -MT crypto/dsa/libfips-lib-dsa_vrf.o -c -o crypto/dsa/libfips-lib-dsa_vrf.o crypto/dsa/dsa_vrf.c gcc -Icrypto/ec/curve448/arch_32 -Icrypto/ec/curve448 -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM - DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM - DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" - DENGINESDIR="\"/usr/local/lib/engines-3\"" -DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/ec/curve448/arch_32/libfips-lib- f_impl.d.tmp -MT crypto/ec/curve448/arch_32/libfips-lib-f_impl.o -c -o crypto/ec/curve448/arch_32/libfips-lib-f_impl.o crypto/ec/curve448/arch_32/f_impl.c gcc -Icrypto/ec/curve448/arch_32 -Icrypto/ec/curve448 -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM - DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM - DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" - DENGINESDIR="\"/usr/local/lib/engines-3\"" -DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/ec/curve448/libfips-lib-curve448.d.tmp -MT crypto/ec/curve448/libfips-lib-curve448.o -c -o crypto/ec/curve448/libfips-lib-curve448.o crypto/ec/curve448/curve448.c gcc -Icrypto/ec/curve448/arch_32 -Icrypto/ec/curve448 -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM - DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM - DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" - DENGINESDIR="\"/usr/local/lib/engines-3\"" -DMODULESDIR="\"/usr/local/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -MMD -MF crypto/ec/curve448/libfips-lib- curve448_tables.d.tmp -MT crypto/ec/curve448/libfips-lib-curve448_tables.o -c -o crypto/ec/curve448/libfips-lib-curve448_tables.o crypto/ec/curve448/curve448_tables.c gcc -Icrypto/ec/curve448/arch_32 -Icrypto/ec/curve448 -I. -Icrypto -Iinclude -Iproviders/implementations/include -Iproviders/common/include -DAES_ASM -DBSAES_ASM - DECP_NISTZ256_ASM -DFIPS_MODULE -DGHASH_ASM -DKECCAK1600_ASM -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DSHA1_ASM - DSHA256_ASM -DSHA512_ASM -DVPAES_ASM -DX25519_ASM -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" - /root/bs/openssl-master

  7. cp_a_to_b cp_a_to_c cp_passwd_to_passwd.save cp passwd.save_to_passwd //a program to copy a file named a to a file named b // a program to copy a file named a to a file named c //a program to copy a file named passwd to a file named passwd.save //a program to copy a file named passwd.save to a file named passwd of course this is ridiculous, instead we just have one program named $ cp and we use command line parameters to name the source file and the destination file $ cp a b $ cp passwd passwd.save in all cases, we run the same program, namely: cp

  8. C every program has to start executing someplace some statement needs to be the first to execute the convention is that the function/method/subroutine java named: main is where it kicks off kotlin there is always an array of strings available in main even though your code has not yet done anything, somehow there is an array of strings already waiting for it

  9. rust python fortran cobol the syntax / stylization can vary a bit, but that string array is always available

  10. this is cut/paste from cp.c, the source code for our cp command when you run: $ cp passwd passwd.save argv[1] = passwd argv[2] = passwd.save

  11. environment variables are used in much the same way a value which comes from outside used by a program, so one does not need to recompile with different values so, what is the difference between command line parameters and environment variables?

  12. a program retrieving the value of an environment variable named HOME a program retrieving the value of command line arguments char *str; public static void main(String[] args) { str = getenv( HOME ); Socket s = null; s= new Socket(args[0],Integer.parseInt(args[1])); but where does it come from? who/what maintains HOME? are there others? how many? how does one create/delete/edit them?

  13. I use ssh to log in to 68.183.19.99, ssh (the program I run) makes a socket connection to sshd - the program running on 68, which is the server waiting for incoming ssh connections. 68> tty /dev/pts/0 68> ps -elf | grep "pts/0" 4 S root 490660 726 0 80 0 - 16695 poll_s 12:58 ? 00:00:00 sshd: root@pts/0 4 S root 490701 490660 0 80 0 - 3012 wait 12:58 pts/0 00:00:00 -bash this is my shell, the one with the 68> prompt and this is the parent of my shell 68> cat p1.c now, using my shell, I am going to run the program p1: int main() { 68> 68> p1 root@itecE:~# this is p1 it runs another shell system("/bin/bash"); }

  14. processId parentId 4 S root 490660 726 0 80 0 - 16695 poll_s 12:58 ? 00:00:00 sshd: root@pts/0 4 S root 490701 490660 0 80 0 - 3012 wait 12:58 pts/0 00:00:00 -bash 4 S root 490740 726 0 80 0 - 16708 poll_s 13:00 ? 00:00:00 sshd: itec10 [priv] 4 S itec10 490753 1 0 80 0 - 8638 ep_pol 13:00 ? 00:00:00 /lib/systemd/systemd --user 5 S itec10 490754 490753 0 80 0 - 49594 sigtim 13:00 ? 00:00:00 (sd-pam) 5 S itec10 490804 490740 0 80 0 - 16760 poll_s 13:00 ? 00:00:00 sshd: itec10@pts/1 0 S itec10 490805 490804 0 80 0 - 2978 wait 13:00 pts/1 00:00:00 -bash 0 S itec10 490818 490805 1 80 0 - 193332 wait_w 13:00 pts/1 00:00:08 ruby /usr/bin/msfconsole 1 I root 490823 2 0 80 0 - 0 worker 13:00 ? 00:00:00 [kworker/u2:4] 1 I root 490829 2 0 80 0 - 0 worker 13:00 ? 00:00:00 [kworker/0:0] 1 I root 490966 2 0 80 0 - 0 worker 13:06 ? 00:00:00 [kworker/0:2] 1 I root 490972 2 0 80 0 - 0 worker 13:06 ? 00:00:00 [kworker/u2:1] 4 S root 490973 726 0 80 0 - 8873 poll_s 13:06 ? 00:00:00 sshd: [accepted] 5 S sshd 490974 490973 0 80 0 - 8873 poll_s 13:06 ? 00:00:00 sshd: [net] 0 S root 490980 490701 0 80 0 - 555 wait 13:07 pts/0 00:00:00 p1 0 S root 490981 490980 0 80 0 - 616 wait 13:07 pts/0 00:00:00 sh -c /bin/bash 4 R root 491003 490981 0 80 0 - 5464 - 13:08 pts/0 00:00:00 ps -elf sshd 490660 bash 490701 p1 490980 68> 68> p1 root@itecE:~# ps elf ps elf 491003 bash 490981 watch as I exit/end each shell

  15. char *str; str = getenv( HOME ); but where does it come from? your parent process #include <stdio.h> this array of strings contains your command line arguments int main(argc, argv, envp) int argc; char **argv, **envp; { printf("hello\n"); } this array of strings contains your environment

  16. $ ps -elf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 1 0 0 80 0 - 56291 ep_pol Mar20 ? 00:00:31 /sbin/init 1 S root 2 0 0 80 0 - 0 kthrea Mar20 ? 00:00:00 [kthreadd] 1 I root 4 2 0 60 -20 - 0 worker Mar20 ? 00:00:00 [kworker/0:0H] 1 I root 6 2 0 60 -20 - 0 rescue Mar20 ? 00:00:00 [mm_percpu_wq] 1 S root 7 2 0 80 0 - 0 smpboo Mar20 ? 00:01:11 [ksoftirqd/0] ... 5 S root 656 1 0 80 0 - 19488 poll_s Mar20 ? 00:00:45 /usr/sbin/apache2 -k start ... 4 S root 4913 4887 0 80 0 - 5803 wait 23:32 pts/0 00:00:00 -bash 0 T root 4950 4913 0 80 0 - 13928 signal 23:33 pts/0 00:00:00 vi 4 R root 4968 4913 0 80 0 - 10025 - 23:34 pts/0 00:00:00 ps -elf

  17. $ cd /proc $ ls 1 165 20 26290 31431 4104 4913 588 7 buddyinfo fb kpagecgroup pagetypeinfo sysvipc 10 17 21 26292 32104 414 493 589 78 bus filesystems kpagecount partitions thread-self 11 18 22 26293 32105 417 5035 590 79 cgroups fs kpageflags sched_debug timer_list 115 18275 23 26294 34 418 5040 591 8 cmdline interrupts loadavg schedstat tty 12 18276 24 26295 343 421 5041 6 80 consoles iomem locks scsi uptime 12849 18277 24508 27 345 422 5046 601 81 cpuinfo ioports mdstat self version 13 18278 24509 28 346 423 570 608 82 crypto irq 14 18280 25 288 35 424 574 617 83 devices kallsyms misc softirqs vmallocinfo 14258 18556 25058 29 36 4250 577 645 89 diskstats kcore modules stat vmstat 15 18557 26 30 3881 428 578 646 9 dma key-users mounts swaps zoneinfo 16 19 26286 3136 4 4439 584 656 98 driver keys mtrr sys 164 2 26289 31424 406 4887 586 659 acpi execdomains kmsg net sysrq-trigger $ cd 1 $ ls attr cmdline environ io mem ns pagemap sched smaps_rollup syscall wchan autogroup comm exe limits mountinfo numa_maps patch_state schedstat stack task auxv coredump_filter fd loginuid mounts oom_adj personality sessionid stat timers cgroup cpuset fdinfo map_files mountstats oom_score projid_map setgroups statm timerslack_ns clear_refs cwd gid_map maps net oom_score_adj root smaps status uid_map meminfo slabinfo version_signature $ pwd /proc/1 $ $ cat environ biosdevname=0HOME=/init=/sbin/initNETWORK_SKIP_ENSLAVED=recovery=TERM=linuxdrop_caps=BOOT_IMAG E=/boot/vmlinuz-4.15.0-206-genericPATH=/sbin:/usr/sbin:/bin:/usr/binPWD=/rootmnt=/root$

  18. 68> env SSH_CONNECTION=174.250.12.6 38118 68.183.19.99 22 LESSCLOSE=/usr/bin/lesspipe %s %s LANG=C.UTF-8 XDG_SESSION_ID=28605 USER=root PWD=/root HOME=/root SSH_CLIENT=174.250.12.6 38118 22 XDG_SESSION_TYPE=tty XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop SSH_TTY=/dev/pts/0 TERM=xterm SHELL=/bin/bash XDG_SESSION_CLASS=user LOGNAME=root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games :/usr/local/games:/snap/bin PS1=68> //show me all your environment variables(talking to the shell here) first, notice the structure (or lack of it) each is a single string, everything to the left of = is the variable name everything to the right is the variable value (no blanks)

  19. 68> env SSH_CONNECTION=174.250.12.6 38118 68.183.19.99 22 LESSCLOSE=/usr/bin/lesspipe %s %s LANG=C.UTF-8 XDG_SESSION_ID=28605 USER=root PWD=/root HOME=/root SSH_CLIENT=174.250.12.6 38118 22 XDG_SESSION_TYPE=tty XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop SSH_TTY=/dev/pts/0 TERM=xterm SHELL=/bin/bash XDG_SESSION_CLASS=user LOGNAME=root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games :/usr/local/games:/snap/bin PS1=68> //show me all your environment variables PS1 USER PWD HOME SHELL PATH what are some of these used for?

  20. so why have two mechanisms? command line arguments user controlled/specified what I want the program to do this time ssh l root 68.183.19.99 //log in to 68.183.19.99 as the user named root ssh -l rjoyce9 rucs.radford.edu //log in to rucs as the user named rjoyce9 environment variables user controlled, or application controlled, or OS controlled, or configuration parameters where is the top of the website subtree? user env information what is the current dir? what is my home dir? what shell am I using? can be fundamental to application function PATH environment variable for a shell or PS1/PS2 for prompts; CLASSPATH for java; LD_LIBRARY_PATH to find dynamic libraries each application can use one or more for their own purposes

  21. shell support for creating, displaying, changing, destroying environment variables 68> XYZ=someValue 68> //assignment brings it into existence or changes //what is was, if it already existed 68> XYZ2="some other value 68> //use if you need to embed spaces (almost //always a bad idea) 68> echo $XYZ2 some other value 68> 68> unset XYZ2 68> 68> echo $XYZ2 //show me the current value, $ means substitute //the actual value, it is not part of the env name //get rid of it 68> XYZ2=" 68> 68> echo $XYZ2 //or set it to be something which doesn t show //those are different things

  22. opportunity to change env when a user logs in $ cd $ ls -la .profile -rwxr-xr-x 1 rjoyce9 Domain Users 1250 Aug 10 2020 .profile //per user $ ls -l /etc/profile -rwxr-xr-x 1 rjoyce9 Domain Users 5625 Apr 20 2020 /etc/profile //for everyone

  23. current Ubuntu default /etc/profile

  24. $ cat .profile -------------------------- # User dependent .profile file ... # Set user-defined locale export LANG=$(locale -uU) # This file is not read by bash(1) if ~/.bash_profile or ~/.bash_login # exists. # # if running bash if [ -n "${BASH_VERSION}" ]; then if [ -f "${HOME}/.bashrc" ]; then source "${HOME}/.bashrc" fi fi alias vi=vim

  25. ` backtick, backquote, grave, grave accent ASCII code: 0x60 single quote (left or right), apostrophe, prime ASCII code: 0x27 double quote (left or right) ASCII code: 0x22 note the reach of ASCII https://www.ascii-code.com/character/%60

  26. $ ls PATH ls: cannot access 'PATH': No such file or directory $ ls $PATH ls: cannot access '/usr/local/bin:/usr/bin:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOW S:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cygdrive/c/WINDOWS/System32/ OpenSSH:/cygdrive/c/Program': No such file or directory ls: cannot access 'Files/Intel/WiFi/bin:/cygdrive/c/Program': No such file or directory $ $ ls '$PATH' ls: cannot access '$PATH': No such file or directory $ $ ls "$PATH" ls: cannot access '/usr/local/bin:/usr/bin:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOW S:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cygdrive/c/WINDOWS/System32/ OpenSSH:/cygdrive/c/Program Files/Intel/WiFi/bin:/cygdrive/c/Program Files/Common Files/Intel/WirelessCommon:/cygdrive/c/Program Files/dotnet:/cygdrive/c/Users/rjoyce9/AppData/Local/Microsoft/WindowsApps': No such file or directory $ $ $ ls `$PATH` -bash: /usr/local/bin:/usr/bin:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS :/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cygdrive/c/WINDOWS/System32/O penSSH:/cygdrive/c/Program: No such file or directory '$Recycle.Bin' cygwin64 Intel pagefile.sys ProgramData 'System Volume Information' '$WINRE_BACKUP_PARTITION.MARKER' 'Documents and Settings' itec445 PerfLogs Recovery Users '$WinREAgent' DumpStack.log.tmp MSOCache 'Program Files' Software

  27. $ cat nf hello i am the data file $ export NEWF="cat nf" $ $ $ NEWF -bash: NEWF: command not found $ $ $NEWF hello i am the data file $ `$NEWF` -bash: hello: command not found $

  28. 68> PS1="`date`> //the backticks mean first run the program inside //them and put the program output right here , then proceed Sun Apr 17 13:49:56 EDT 2022> //PS1 is the (1st) prompt, note the use of //so we can have a blank after > , also //note that backtick works inside double quotes Sun Apr 17 13:49:56 EDT 2022> PS1= > > PS1= `date`> Sun Apr 17 14:02:48 EDT 2022> Sun Apr 17 14:02:48 EDT 2022> //note the date prompt is not changing, once set //but now it is changing, each <cr> gets a new prompt, what s different? Sun Apr 17 14:02:48 EDT 2022> PS1='`date`> ' Sun Apr 17 14:02:57 EDT 2022> Sun Apr 17 14:02:59 EDT 2022> Sun Apr 17 14:03:02 EDT 2022>

  29. > > NEWONE='this-$HOME-isMyValue > > echo $NEWONE this-$HOME-isMyValue > > NEWONE="this-$HOME-isMyValue > echo $NEWONE this-/root-isMyValue > //single quote vs double again // $ substitution happens inside double quotes // but not inside single quotes

  30. the shell built-in: env prints the full list

  31. two more tidbits: these environment variables are also used for variables in the built-in shell programming language: > for i in { c .. f } > do > echo $i > done c d e f //they can be //used as numbers //as well

  32. $ for i in aa bb cc3d > do > echo $i > done aa bb cc3d $ ls a2a aa b3b bb cc dd ee $ for i in `ls` > do > echo $i > done a2a aa b3b bb cc dd ee $ for i in ls > do > echo $i > done ls $ for i in `'ls'` > do > echo $i > done a2a aa b3b bb cc dd ee $ for i in '`ls`' > do > echo $i > done `ls` $ for i in `"ls"` > do > echo $i > done a2a aa b3b bb cc dd ee $ for i in 'ls' > do > echo $i > done ls $ for i in "`ls`" > do > echo $i > done a2a aa b3b bb cc dd ee

  33. tidbit number 2, the use of export p2 prints out the value of an environment variable named SOMEVAR SOMEVAR has no value, even after I set it export says - pass this new one along to child processes

  34. As with many concepts, Microsoft has copied and/or converged upon *NIX over the years. Also typical of MS, there are different footprints remaining from the evolution. On Windows, environment variables can be defined in three scopes: Machine (or System) scope User scope Process scope https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.2

  35. cmd.exe powershell

  36. some different shell options sh - bourne shell (Steve Bourne) first shell, no command line history; easy to underestimate inertia still the least common denominator choice of safety csh - C shell Berkley folks (Bill Joy), soon after the first fork sys5 vs 4.2 Berkley ksh - Korn Shell (David Korn) another btl guy, essentially sh+; became most popular at btl bash - GNU Bourne again shell, bash shell xsh x=xml, x=Xwindows, zsh, inter alia

  37. step 1: echo aaa > dataFile echo bbb >> dataFile echo ccc >> dataFile export FILE= dataFile #!/bin/bash a=10 b=20 if [ $a -gt $b ] then echo "a is greater than b" else echo "a is less than b" fi environment variables used as typical variables for base data type in the shell programming languages step 2: vi nextProgram: #!/bin/bash while read line; do echo $line done #!/bin/bash n=0 while [ $n -le 5 ] do echo Number: $n ((n++)) done $ ./nextProgram < $FILE

  38. shell development example http://www.bolthole.com/solaris/ksh-sampleprog.html

  39. Given: $ date Mon Apr 10 19:48:49 EDT 2023 $ $ V1="date" $ V2='"date"' $ V3=`date`$V2 $ V4='$V1$V2' What do you see for each? a) echo V1 ____________________________________________ b) echo $V2 ____________________________________________ c) echo $V3 ____________________________________________ d) echo $V4 _____________________________________________

Related


More Related Content