File tree 1 file changed +17
-3
lines changed 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
/* Simple shell
2
- * September 18, 2010 */
2
+ * September 18, 2010
3
+ * November 21, 2024 */
3
4
#include <stdio.h>
4
5
#include <stdlib.h>
5
6
#include <string.h>
8
9
9
10
int main (int argc , char * argv []) {
10
11
char x [256 ], y [256 ], z [256 ];
12
+ char host [60 ];
13
+ char * user = getlogin ();
14
+
15
+ if (!user ) {
16
+ fprintf (stderr , "Could not get current user\n" );
17
+ return 1 ;
18
+ }
19
+
20
+ gethostname (host , sizeof (host ));
21
+
11
22
while (1 ) {
12
- getcwd (y , sizeof (y ));
13
- printf ("%s$ " , y );
23
+ printf ("[%s@%s]$ " , user , host );
14
24
fgets (x , sizeof (x ), stdin );
15
25
if (x [0 ] == 'c' && x [1 ] == 'd' && x [2 ] == ' ' ) {
16
26
sscanf (x , "cd %s" , z );
17
27
chdir (z );
18
28
}
29
+ else if (x [0 ] == 'p' && x [1 ] == 'w' && x [2 ] == 'd' && x [3 ] == '\n' ) {
30
+ getcwd (y , sizeof (y ));
31
+ printf ("%s\n" , y );
32
+ }
19
33
else if (strcmp (x , "exit\n" ) == 0 ) break ;
20
34
else system (x );
21
35
}
You can’t perform that action at this time.
0 commit comments