-1

Please consider:

cd ~
cd $HOME

I would say that the first command is a possible sugar syntax of the second command, and that the second is less abstract.


Just for the sake of demonstrating how commands can become less and less abstract to newcomers to programming (in the context of explaining what is abstraction), focusing on shell, I ask:
How to translate a non sugary syntactic shell (Bash) command into "lower" types of code such as assembly or even machine code (or to anything coming between, say cd $HOME to its assembly representation)?
What software I could use, perhaps in shell, to achieve this goal to demonstrate how a computer command goes from the simple to the complicated?

terdon
  • 242,166
  • Given how cd translates almost directly to the chdir() system call, turning it into low level operations is either trivial (if you stop at the system call), or quite complicated (given that the system call modifies process state kept in the OS, and that calls in the very concept of a process as unit of execution separated from other processes...) – ilkkachu May 07 '21 at 16:14
  • 1
    This site is not your personal soap box. Please limit your questions and answers to technical discussion. Nothing else is welcome here. If you have an issue with an answer, please flag it for moderator attention but don't use your posts to make personal points. – terdon May 07 '21 at 16:18

2 Answers2

0

Since you mention Bash, translating cd into assembly language can be done as follows:

git://git.savannah.gnu.org/bash.git
cd bash
./configure
make
cd builtins
./mkbuiltins -D . cd.def
gcc -S -DHAVE_CONFIG_H -DSHELL  -I. -I..  -I.. -I../include -I../lib -I.    -g -O2 -Wno-parentheses -Wno-format-security cd.c

You’ll then find the corresponding assembly language in builtins/cd.s. (You’ll need a number of development tools installed; how to do that depends on your distribution, and ./configure will tell you what’s missing.)

I doubt this will be very useful, especially for newcomers to programming.

Stephen Kitt
  • 434,908
0

To execute high level shell commands, you need a complex program, the shell.

No amount of assembly or machine code will change the current directory of a process, unless it is the sequence of instructions that calls the kernel. The kernel is even more complex software than the shell, and there is nothing simple about the execution of the chdir, there are again layers of filesystem abstraction.

In general, there is little to gain from assembly or machine code, especially for newcomers to programming.

terdon
  • 242,166
RalfFriedl
  • 8,981
  • 1
    @timesharer we expect all users here to be polite and civil. Your comments are out of line and I have deleted them. Ralfriedl, please avoid characterizing the OP. There is no call for that. I have removed that from your answer. – terdon May 07 '21 at 15:51