How do you create a shell script?

Helen Schofield

I need to create a shell script that will create a user then put it into a group. How do I do it?

FortuneCookie101

Your question is a bit vague because you haven't really said what you need this for.

I'm assuming you need arguments as well so first create the script, so in the terminal type nano scriptname.sh and past in the script below.

#!/bin/bash

#$1 username
#$2 home directory

useradd $1 -U -m -d $2

If you type 'man useradd' you will see that -U creates a group with the same name as the user, -m creates the home directory and -d specifics the path to the home directory.

To use this script type chmod +x scriptname.sh to make the script executable and then type ./scriptname.sh

So for example to create a user called bob with the users home being /home/bob type:

./scriptname.sh bob /home/bob

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Linux

How do you write a linux shell script to manipulate filenames and create new file

From Dev

How do you effectively use the 'script' command to record an interactive shell?

From Dev

How do you run functions and variables from shell script into docker?

From Dev

How do you echo a question mark in a shell script?

From Dev

How do you set the exit status of a shell script?

From Dev

How to create a shell script

From Dev

How do you create a custom application launcher in Gnome Shell?

From Dev

How do I create the Windows Equivalent of This Very Small Shell Script?

From Dev

How to create a Loop in Shell Script to do a specific task?

From Dev

how do i create a shell script with multiple choice menu variables?

From Dev

How do you create a new script in Greasemonkey 4?

From Dev

How do you create a LLDB script to ignore SIGSEGV and SIGBUS

From Dev

How do you create a shortcode function to run a script within a page?

From Dev

How to create a shell script with the systemctl

From Dev

How do you use variables with values containing spaces in a Z-shell (zsh) script command?

From Dev

How do you implement process substitution (using a bash script) in a shell that doesn't have it?

From Dev

How do you calculate sum of a column without creating temp files in shell script?

From Dev

How do you run a shell command/script automatically when entering/cd-ing a directory on Snow Leopard?

From Java

How do you create a maven assembly that includes shell scripts and properrties file not in jar?

From Dev

How do you create an RS256 JWT assertion with bash/shell scripting?

From Dev

How do you create a Rakefile?

From Dev

How do you create indicators?

From Dev

How do you get a shell on a Mac?

From Dev

How do you stop a bash shell expansion?

From Dev

How do you replace the logon shell with iexplore?

From Dev

How do i run a shell script, in a shell script with the menu dialog?

From Dev

How to create a shell script with the comand cal

From Dev

How create a temporary file in shell script?

From Dev

How can I create a shell script shortcut?

Related Related

  1. 1

    How do you write a linux shell script to manipulate filenames and create new file

  2. 2

    How do you effectively use the 'script' command to record an interactive shell?

  3. 3

    How do you run functions and variables from shell script into docker?

  4. 4

    How do you echo a question mark in a shell script?

  5. 5

    How do you set the exit status of a shell script?

  6. 6

    How to create a shell script

  7. 7

    How do you create a custom application launcher in Gnome Shell?

  8. 8

    How do I create the Windows Equivalent of This Very Small Shell Script?

  9. 9

    How to create a Loop in Shell Script to do a specific task?

  10. 10

    how do i create a shell script with multiple choice menu variables?

  11. 11

    How do you create a new script in Greasemonkey 4?

  12. 12

    How do you create a LLDB script to ignore SIGSEGV and SIGBUS

  13. 13

    How do you create a shortcode function to run a script within a page?

  14. 14

    How to create a shell script with the systemctl

  15. 15

    How do you use variables with values containing spaces in a Z-shell (zsh) script command?

  16. 16

    How do you implement process substitution (using a bash script) in a shell that doesn't have it?

  17. 17

    How do you calculate sum of a column without creating temp files in shell script?

  18. 18

    How do you run a shell command/script automatically when entering/cd-ing a directory on Snow Leopard?

  19. 19

    How do you create a maven assembly that includes shell scripts and properrties file not in jar?

  20. 20

    How do you create an RS256 JWT assertion with bash/shell scripting?

  21. 21

    How do you create a Rakefile?

  22. 22

    How do you create indicators?

  23. 23

    How do you get a shell on a Mac?

  24. 24

    How do you stop a bash shell expansion?

  25. 25

    How do you replace the logon shell with iexplore?

  26. 26

    How do i run a shell script, in a shell script with the menu dialog?

  27. 27

    How to create a shell script with the comand cal

  28. 28

    How create a temporary file in shell script?

  29. 29

    How can I create a shell script shortcut?

HotTag

Archive