File: add_script_argument

package info (click to toggle)
sash 3.8-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 768 kB
  • sloc: ansic: 8,177; makefile: 47; sh: 10
file content (64 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Description: read the input from a file specified on the command line
 This to use sash as a #! interpreter.
 <long description that can span multiple lines, optional>
Origin: https://github.com/OpenMandrivaAssociation/sash/blob/rolling/sash-3.6-scriptarg.patch

--- a/sash.c
+++ b/sash.c
@@ -527,6 +527,24 @@ main(int argc, const char ** argv)
 		}
 	}
 
+	/* A single argument is allowed, and it must be a filename which
+	   provides stdin. This allows #! usage. */
+	if (argc) {
+		int fd;
+
+		fd = open(argv[0], O_RDONLY);
+		if (fd < 0) {
+			fprintf(stderr, "Error opening %s: %s\n", argv[0],
+				strerror(errno));
+			return 1;
+		}
+
+		dup2(fd, 0);
+		close(fd);
+
+		argc--, argv++;
+	}
+
 	/*
 	 * No more arguments are allowed.
 	 */
@@ -1344,6 +1362,7 @@ usage(void)
 	fprintf(stderr, "Stand-alone shell (version %s)\n", version);
 	fprintf(stderr, "\n");
 	fprintf(stderr, "Usage: sash [-a] [-q] [-f fileName] [-c command] [-p prompt] [-i]\n");
+	fprintf(stderr, "Usage: sash [-a] [-q] [-f fileName] [-c command] [-p prompt] [-i] [script]\n");
 
 	exit(1);
 }
--- a/sash.1
+++ b/sash.1
@@ -2,7 +2,7 @@
 .SH NAME
 sash \- stand-alone shell with built-in commands
 .SH SYNOPSYS
-.B sash [-c command] [-f fileName ] [-p prompt] [-q] [-a]
+.B sash [-c command] [-f fileName ] [-p prompt] [-q] [-a] [script]
 .SH DESCRIPTION
 The
 .B sash
@@ -525,6 +525,12 @@ This option is also implied if the -c or
 The -a option creates aliases for the built-in commands so
 that they replace the corresponding standard commands.
 This is the same result as if the 'aliasall' command was used.
+
+A file name may be provided as the last argument to sash, in which case
+sash's standard input is read from that file. This allows #! scripts
+to use sash as their script interpreter. Be aware that sash does not provide
+most normal bourne-shell programming features, however.
+
 .SH SYSTEM RECOVERY
 This section contains some useful information about using
 .B sash